File Management
To manipulate file (upload
, write
or downlaod
), you need to generate a PreSignUrl
When Uploading or Writing a file, it will automatically generate a new thumbnail for this file. You can disabling it by providing should_not_generate_thumbnail=true
as Query params (second parameter of this uploadApplicationFile
function
Upload File
// Generate a preSignUrl
const resultPreSignUrl = await getPreSignedUrlApplicationFile(
{ applicationId: "my-application-id" },
{
type: PreSignUrlType.UPLOAD,
fileName: fileToUpload.name,
},
);
const transfer = new Transfer({
name: "My Transfer",
type: TransferType.UPLOAD,
});
transfer.setAction(() => {
// Set any action to trigger on Upload/Download Progression
});
// Use the PreSignUrl to upload the file
await uploadApplicationFile(
{ token: resultPreSignUrl.data.preSignUrl },
{},
file,
{ transfer },
);
Write File
// Generate a preSignUrl
const resultPreSignUrl = await getPreSignedUrlApplicationFile(
{
applicationId: "my-application-id",
applicationFileId: "file-id"
},
{
type: PreSignUrlType.WRITE,
},
);
const transfer = new Transfer({
name: "My Transfer",
type: TransferType.UPLOAD,
});
transfer.setAction(() => {
// Set any action to trigger on Upload/Download Progression
});
// Use the PreSignUrl to write the new file
await writeApplicationFile(
{ token: resultPreSignUrl.data.preSignUrl },
{},
file,
{ transfer },
);
Download File
// Generate a preSignUrl
const resultPreSignUrl = await getPreSignedUrlApplicationFile(
{
applicationId: "my-application-id",
},
{
type: PreSignUrlType.DOWNLOAD,
userApplicationFileId: userApplicationFile.id,
},
);
const transfer = new Transfer({
name: "My Transfer",
type: TransferType.DOWNLOAD,
});
transfer.setAction(() => {
// Set any action to trigger on Upload/Download Progression
});
// Use the PreSignUrl to downloadthe new file
const result = await downloadApplicationFile(
{ token: resultPreSignUrl.data.preSignUrl },
{ transfer },
);
Publish a file
Each file get be accessed from PreSignUrl
but you can also enable a public access link to let anybody download your file, such as a Image Provider for your Website
// By reseting the PublicAccess, you can also enable it
await resetPublicAccessApplicationFile({
applicationId: "application-id",
applicationFileId: "application-file-id",
});
// You can also disable this feature by unsetting the PublicAccess
await unsetPublicAccessApplicationFile({
applicationId: "application-id",
applicationFileId: "application-file-id",
});
Upload from an external link
You can provide a link referring to a file to upload it to your storage.
await uploadFromUrlApplicationFile(
{ applicationId: "application-id" },
{
name: "filename.png",
url: "https://some-url.com/file/download",
},
);
Last updated