4.0.2 • Published 3 days ago
@uplift-ltd/file-uploads v4.0.2
@uplift-ltd/file-uploads
Installation
npm i --save @uplift-ltd/file-uploads
API
File upload related functionalities for web and React Native.
useUploadFile
Upload a single file.
import { useUploadFile } from "@uplift-ltd/file-uploads";
interface UseUploadFileOptions {
onProgress?: (progress: number, fileAttachment: S3FileAttachment) => void;
onLoading?: (loading: boolean, fileAttachment: S3FileAttachment) => void;
onComplete?: (fileAttachment: S3FileAttachment) => void;
onError?: (error: Error, fileAttachment: S3FileAttachment) => void;
}
function MyComponent() {
const { uploadFile, fileAttachment, loading, error } = useUploadFile();
<input
type="file"
onChange={(e) => {
if (!e.target.files) {
return;
}
Array.from(e.target.files).forEach((file) => {
uploadFile({
file,
grapheneId: "VXNlcjox",
appLabel: "runbook",
isDraft: true,
metadata: { caption: "Brooo" },
});
});
}}
/>;
}
useUploadFiles
Upload multiple files.
import { useUploadFiles } from "@uplift-ltd/file-uploads";
function MyComponent() {
const {
uploadFiles,
onRequestRemove,
fileAttachments,
fileAttachmentsById,
loadingById,
errorById,
progressById,
progress, // total / num files
loading, // any loading
} = useUploadFiles();
<input
type="file"
onChange={(e) => {
if (!e.target.files) {
return;
}
uploadFiles(Array.from(e.target.files));
}}
/>;
}
Custom signed request
To use a custom signed request:
// MyComponent.tsx
useUploadFile({ signedRequestOptions: { query: MY_SIGNED_REQUEST_MUTATION } });
// OR
useUploadFiles({ signedRequestOptions: { query: MY_SIGNED_REQUEST_MUTATION } });
// file-uploads.d.ts
import "@uplift-ltd/file-uploads";
declare module "@uplift-ltd/file-uploads" {
export interface GetSignedRequestMutationVariables {
recaptchaToken: string;
}
}
4.0.2
3 days ago
3.0.5
9 months ago
4.0.1
6 months ago
4.0.0
6 months ago
4.0.1-alpha.0
6 months ago
4.0.1-alpha.1
6 months ago
3.0.4
11 months ago
3.0.3
1 year ago
3.0.4-alpha.0
1 year ago
4.0.0-alpha.1
1 year ago
4.0.0-alpha.2
1 year ago
4.0.0-alpha.0
1 year ago
3.0.2
1 year ago
3.0.1
1 year ago
3.0.0-alpha.0
1 year ago
3.0.0
1 year ago
2.0.6
1 year ago
2.0.5
1 year ago
2.0.5-alpha.3
1 year ago
2.0.5-alpha.1
1 year ago