In the earlier blog I’ve showed how to generate authentication token for our object storage .In this blog I will show how to upload file in to object storage using that token.
So once we have our token we can use that to store files in the container.
In this blog I will create an api , using which we can upload a file in to object storage container.
For uploading any file through api , it is better that the file data should be passed to api as base64.Then it should be decoded and stored in object storage.
For uploading a file to objectstorage an api is provided which is,
API_ENDPOINT + ‘/’ + pdf_container_name + ‘/’ + pdfFileName
METHOD : PUT
Here API_ENDPOINT is mentioned in the previous blog
Here token is the one which we generated and Content-Type depends on the file type.
First we will create a function which would accept the base64 data and the name with which it should be stored in object storage(eg: document.pdf)
We are passing the base64 data as Stream and then we are decoding the base64 data and pipe() that data to our request.
Then in our main api we will call the above function as below :
Here we are appending timestamp to the filename ,storing the file in object storage and then we are sending that as response to this rest call.
Then we call use this api at our client side and server side and then upload your document.
Hope it helps someone.