MCPcopy Index your code
hub / github.com/CapSoftware/Cap / uploadNativeFile

Function uploadNativeFile

apps/mobile/src/api/mobile.ts:326–355  ·  view source on GitHub ↗
(
	method: "POST" | "PUT",
	url: string,
	file: UploadFile,
	options: FileSystem.FileSystemUploadOptions,
	onProgress?: (progress: UploadProgress) => void,
)

Source from the content-addressed store, hash-verified

324};
325
326const uploadNativeFile = async (
327 method: "POST" | "PUT",
328 url: string,
329 file: UploadFile,
330 options: FileSystem.FileSystemUploadOptions,
331 onProgress?: (progress: UploadProgress) => void,
332) => {
333 const task = FileSystem.createUploadTask(
334 url,
335 file.uri,
336 {
337 ...options,
338 httpMethod: method,
339 },
340 (data) => {
341 onProgress?.({
342 loaded: data.totalBytesSent,
343 total: data.totalBytesExpectedToSend,
344 });
345 },
346 );
347 const response = await task.uploadAsync();
348 if (!response || response.status < 200 || response.status >= 300) {
349 throw new MobileApiError(
350 "Upload target rejected the file",
351 response?.status ?? 0,
352 response?.body ?? null,
353 );
354 }
355};
356
357const uploadWithXhr = (
358 method: "POST" | "PUT",

Callers 1

uploadToTargetFunction · 0.85

Calls 1

onProgressFunction · 0.50

Tested by

no test coverage detected