How to Upload a File/Resume(.doc and .pdf) in Object Storage Programatically

November 29, 2017 87 views
Block Storage CentOS

I have my code written in JQuery where I am uploading a file (resume)
var input = document.getElementById('resumeFile);
var file = input.files[0];
$.post({
url: "url of the space-object storage",
data : file,
success: function(response) {
alert('Success'+response);
},
error: function(error) {
alert('Failed');
}

I dont see the file in the space. Can someone throw some light where I am going wrong

1 Answer

Hi,

Spaces requires authentication for uploads. I strongly recommend that you move this logic to the back-end as you definitely do not want your API key sent to all visitors to be used by client-facing jQuery—it gives everyone the ability to view all your Spaces and perform all kinds of operations on them including downloading all data and deleting it.

You should be able to use any S3-compatbile library so depending on which language the backend is written in. Here is an example for Node.js: https://www.digitalocean.com/community/tutorials/how-to-upload-a-file-to-object-storage-with-node-js

For reference, documentation on the Spaces API is available here: https://developers.digitalocean.com/documentation/spaces/

Create a Node.js app to upload a file to your DigitalOcean Space
Have another answer? Share your knowledge.