Is there a way to download a file?

Hi.

Is there a way to download a file I just uploaded to the server?

If yes, It’d be really good to know how.

Thanks.

Have you tired network.download()?

https://docs.coronalabs.com/api/library/network/download.html

EDIT: I’m dumb. Sorry for the useless post :frowning:

Hi,

If you’ve uploaded the file using the Coronium module, you should receive a path to that file in the return (generally you would associate this with some data record). And then you would use network.download as suggested.

Cheers.

Useless post? I don’t think so! Thanks, Alex. I didn’t think of network.download.

Thanks. :slight_smile:

And another thing: I think I found a bug in your code.
The function below is returning nil. Can you confirm that?
–File is done uploading.
local function onFileUpload( event )
if not event.error then
print( event.result.objectId )
end
end

I’ll take a look. I assume you’re running all the latest versions?

The first version I used was almost a year ago, and this issue was already there. In the rush of the year I forgot to point it out to you and focused on other things.

 I did download the latest version yesterday. 

I know this post is a bit old, but I found the solution to event.result.objectId.  It will return nil everytime… but if you look for event.result.file, you will get what you’re looking for.

For my app, I’ve figured out how to output to a txt file, zip that file, upload to Coronium, get the download link returned, download, unzip, extract from text.  The only thing I’m lacking now is the ability to delete the .zip file that was uploaded on the server.  Does anyone out there know how to do that?  I’m assuming it something involving network.request, but I’m really have trouble understanding that call and figuring out how to delete a file.

Any help would be greatly appreciated.

Here’s the code I’m trying to run… maybe it’s something simple:

[lua]

local function networkListener( event )

     if ( event.isError ) then

     elseif ( event.phase == “began” ) then

     elseif ( event.phase == “ended” ) then    

     end

end

network.request(downloadLink, “DELETE”, networkListener)

[/lua]

Hi,

You can’t delete files from the client for security reasons. You would need to do that in cloud Lua, and call from the client.

Check out Lua’s os.remove(filename)

Deletes the file or directory with the given name. Directories must be empty to be removed. If this function fails, it returns nil, plus a string describing the error.

Hope that helps.

I think this will help quite a bit, but I’ll have to get familiar with the concept of Cloud Lua.  My understanding is that you can create a .lua file on the server, or upload one… and call a function on that .lua file using:

[lua]:run( functionName, functionParameters, callback )[/lua]

But I’m not sure how the directory works on the cloud.  What would be the path to access files I uploaded using coronium:uploadFile?

So I’m thinking the function in Cloud Lua would be very simple something like this:

[lua]

local function deleteChallengeFunction(fileToDelete, directoryIn)

    os.remove( system.pathForFile( fileToDelete, directoryIn ) )

end 

[/lua]

I know there’s probably much more to it than this.  I’ll keep researching… but any help would be greatly appreciated.   

Okay, so I’ve followed the tutorial for using Cloud Lua and was able to get responses using coronium.input and coronium.output.  But I’m still at a loss on where to access the files that were uploaded via coronium:uploadFile.  My concern is that the documentation for os.remove() says “You can only remove files in the DocumentsDirectory and TemporaryDirectory”.  I would greatly appreciate any help.

I would really like to be able to delete the file using Cloud Lua… but if that’s not possi nm let, does Coronium support something like this?

Deleting an object will not delete any file that is referenced by any of its columns.

Files are static assets and may be referenced from different places. For example, your app may have cached an object with a reference to this file. Even if the original object has been deleted from the server, cached data should continue working without impacting the user experience in most cases.

If you still want to delete a file, you can do so through the REST API. You will need to provide the master key in order to be allowed to delete a file. Note that the name of the file must be the name in the response of the upload operation, rather than the original filename.

curl -X DELETE \
-H “X-Parse-Application-Id: <YOUR_APPLICATION_ID>” \
-H “X-Parse-Master-Key: <YOUR_MASTER_KEY>” \
https://api.parse.com/1/files/<FILE_NAME>

Hi,

Let me spin up a Coronium instance and I can help you better. When you upload a file you should receive its identifier/url, generally you’d want to store this data so you can easily access it again. The file uploads are logged in MySQL so thats one place to find paths, but…if you know the filename then its not too hard to do.

The documents you refer to in regards to “DocumentsDirectory”, etc. have to do directly with Corona SDK, not Cloud Lua.

Again, let me start up an instance so I can help you better.

Cheers.

You are awesome!  I truly appreciate your help.  

I am tracking the url, to include the file name when I upload the file.  Later the file is downloaded with the returned url by another user.  When the transaction is complete, the user that created the file will need to be able to delete the file… that last bit is the only piece missing.  

Please let me know whatever information you need… and Thanks again.

Wait, one sec. So I’m clear, you want to delete the file from the clients device? Or from the actual Coronium server?

Cheers.

I need it so that the user can delete the file, or call a function that exists in Cloud Lua that will delete the file.  I can write the code to make this automatic or done at the press of a button from the user side.  But the initiation of the deletion needs to start from a user.

There are 2 different actions here (and locations). I’m trying to determine whether you would like to remove the file from both the server and the clients device (after download of course), or just the server, or just the client (Corona SDK)?

Depending on which you want to do, you may not need to do anything with Cloud Lua.

Let me know.

I’m already deleting the file in the device after download using os.remove.  What I need is to be able to delete the file on the server.

Ok, perfect. I’ll get back to you shortly. :slight_smile:

Thanks