Sign In Register

How can we help you today?

Start a new topic
Answered

Cloud storage : delete and browse

Hello,


I have two quick questions:


Is it possible to delete a file uploaded on cloud storage by the API? If yes, I did not find the documentation, can you give the link?


Is it possible to browse the files uploaded with the web interface? Or manage them, see the current quota? 


Thank you


Best Answer

Hi Vincent,


Sorry for the delayed response, I've figured out a way for you to build you own uploadedFiles collection which you can then use to create a file browser in the manage screen. Navigate to Cloud Code>User Messages> UploadCompleteMessage and paste in the code below. With this in place each time you upload a file the critical info you require will also be duplicated into the runtime collection "uploadedFiles"


 

//this will grab the uploadedData that we need from the response
var dataToGrab = Spark.getData().uploadData;

//load the collection
var uploadedFiles = Spark.runtimeCollection("uploadedFiles");

//insert the info into into our collection
var success = uploadedFiles.insert({"uploadedData":dataToGrab})

 


Then I created an event called "deleteUpload" and gave it a single string attribute called "uploadId" set to be "Used In Script", in the cloud code for that event I placed the following.

 

//load the collection
var uploadedFiles = Spark.runtimeCollection("uploadedFiles");

//get the uploadId that we passed in through the event
var uploadId = Spark.getData().uploadId;

//delete the file from the system
Spark.getFiles().deleteUploadedFile(uploadId);

//remove the file from our custom collection
var fileToRemove = uploadedFiles.remove({"uploadedData.uploadId": uploadId });

//display what file has been removed
Spark.setScriptData("File Removed", uploadId);

  

Hope this helps, if you have anymore questions just let me know.


Thanks,

Liam


I found how to delete: by using the Spark.deleteUploadedFile("myUploadId"); from cloud code. But I'm still looking for a way to browse the uploaded file (for admin reason).

Thank you!

Answer

Hi Vincent,


Sorry for the delayed response, I've figured out a way for you to build you own uploadedFiles collection which you can then use to create a file browser in the manage screen. Navigate to Cloud Code>User Messages> UploadCompleteMessage and paste in the code below. With this in place each time you upload a file the critical info you require will also be duplicated into the runtime collection "uploadedFiles"


 

//this will grab the uploadedData that we need from the response
var dataToGrab = Spark.getData().uploadData;

//load the collection
var uploadedFiles = Spark.runtimeCollection("uploadedFiles");

//insert the info into into our collection
var success = uploadedFiles.insert({"uploadedData":dataToGrab})

 


Then I created an event called "deleteUpload" and gave it a single string attribute called "uploadId" set to be "Used In Script", in the cloud code for that event I placed the following.

 

//load the collection
var uploadedFiles = Spark.runtimeCollection("uploadedFiles");

//get the uploadId that we passed in through the event
var uploadId = Spark.getData().uploadId;

//delete the file from the system
Spark.getFiles().deleteUploadedFile(uploadId);

//remove the file from our custom collection
var fileToRemove = uploadedFiles.remove({"uploadedData.uploadId": uploadId });

//display what file has been removed
Spark.setScriptData("File Removed", uploadId);

  

Hope this helps, if you have anymore questions just let me know.


Thanks,

Liam

Thank you for your response.

Login to post a comment