You need to sign in to do that
Don't have an account?
Guntin Guntin L Garcia
Upload a file to Dropbox, Google Drive and any third system
I've developed a code to upload a file to dropbox since LWC. It doesn't work.
The File Upload LWC component returned a ContentDocumentId once the file is uploaded.
The Dropbox API to upload a file requires the file location to send it to the Dropbox folder. I've tried to send in the body the file content, taken from ContentVersion.VersionData but it doesn't work. A file in Dropbox is created with unreadable content.
How could I solve it?
Here is my code
Thanks
The File Upload LWC component returned a ContentDocumentId once the file is uploaded.
The Dropbox API to upload a file requires the file location to send it to the Dropbox folder. I've tried to send in the body the file content, taken from ContentVersion.VersionData but it doesn't work. A file in Dropbox is created with unreadable content.
How could I solve it?
Here is my code
@AuraEnabled public static String uploadFile(Id documentId, Id recordId, String path){ path = createFolder(recordId); Metadata fileMetadata; ContentVersion file = [Select Id, Title, contentdocumentid, FileExtension, VersionData, PathOnClient from ContentVersion where islatest = true and contentdocumentid =: documentId LIMIT 1 ]; GUIJE_OAuthController.OAuth oAuthInstance = GUIJE_OAuthController.getOAuthByName(PROVIDER_NAME); HttpRequest request = new HttpRequest(); if(!String.isBlank(oAuthInstance.access_token)){ request.setHeader('Authorization', String.format('Bearer {0}', new List<String>{oAuthInstance.access_token})); } else { //@todo reset token; } request.setMethod('POST'); request.setTimeout(60000); request.setEndpoint('https://content.dropboxapi.com/2/files/upload'); UploadFile upfile = new UploadFile(path+'/'+file.Title+'.'+file.FileExtension); request.setHeader('Dropbox-API-Arg', JSON.serialize(upfile)); request.setHeader('Content-Type', 'application/octet-stream'); String attachmentBody = EncodingUtil.base64Encode(file.VersionData); request.setBody(attachmentBody); request.setBody(EncodingUtil.base64Encode(file.VersionData)); HttpResponse response = GUIJE_REST.send(request); if (response.getStatusCode() == 201 || response.getStatusCode() == 200) { fileMetadata = (Metadata) JSON.deserialize(response.getBody(), Metadata.class); } else { System.debug(response.getStatus()); fileMetadata = new Metadata(); fileMetadata.error = JSON.serialize(response.getStatus()); } return JSON.serialize(fileMetadata); }
Thanks
Not sure if this will work, Found an Idea link for same.
https://trailblazer.salesforce.com/ideaView?id=08730000000gPLrAAM
You can use below appexchange tool.
https://appexchange.salesforce.com/appxListingDetail?listingId=a0N30000000prqLEAQ
Thanks,