Transferring files between users

Hi,

Does anyone know the best way to transfer a file between different users of a Corona app?  So if both users are using the same Corona app, and I needed the app to be able to transfer a txt file from one user’s system.DocumentsDirectory to another user’s system.DocumentsDirectory directory, what would be the best approach?

In other words, if user 1 creates a note that gets saved to their system.DocumentsDirectory as note1.txt, and he wanted to send that note1.txt to a friend that lives in another state so that user 2’s app could open that note1.txt file…

I tried using the Google Drive plugin so that the app would send the file up to google drive, and the other user’s app would retrieve it there, but that marketplace plugin is no longer supported.

Is the best solution using file upload as described here?

https://coronalabs.com/blog/2014/02/25/tutorial-uploading-files-demystified/

That blog is from 2014 so I’m not sure if it’s obsolete? 

The other problem is I’d have to find a hosting provider that would allow file uploads (They often don’t on shared servers due to security)

Is there another solution I’m not thinking of or is that the only way?

Thanks in advance for your insights!

There are myriad ways to achieve this.

You didn’t say if this was for Android, iOS, or both.  I will assume you only want mobile solutions.

  • iOS Only
  • Both
    • AWS S3 Buckets  - https://marketplace.coronalabs.com/plugin/s3-lite
      • You’ll need an AWS account.  Then you will need to set up a bucket. 
      • Also, for this to work, the reader and writer both have to know the URL of the bucket and the name of the file.  How you will get this information to the receiver I don’t know, depending on how you want it to work.
    • DIY Server - Set up your own server running PHP.  Then, simply upload and download files via PUT and GET respectively using the corona networking library.
    • Corona Cloud - You’ll have to search for this, but it still exists and still works.  This will however be a lot for work to get set up initially.  Setting up the CC is easy, but you’ll have to write code to do this ‘file transfer’ thing and that is a lot of work.
    • Other marketplace solutions - Check it out there are probably other solutions: https://marketplace.coronalabs.com/ 

Note: At the end of the day, this is going to be real work (except for the iOS only solution.  That is easy.)

Note 2: Finding a provider is easy.  You’re just not thinking about the right kinds of providers.  I suggest Digital Ocean.

You left a lot of details out in your request for info, one key piece of info was the answer to this question:

“Is this shared file private between the two parties, or can any one with the app access the file?”  

If it is private, you are going to need to set up methods to:

  • Uniquely name the file when party A saves/sends it.
  • Asynchronously notify party B of the file name and the fact that the file has been written.
  • Download the file to party B’s device.

If it is not private, this implies to me that all apps are saving and reading the same file.  That seems unlikely.  However if that is the case, then you have to provide a means of dealing with the producer-consumer problem.

If however, you have a single producer and everyone else is consumer this becomes simple to coordinate.

Thanks SO much for the detailed and highly-organized reply!  This is very helpful. I’m actually mostly developing for Android. I’ll study your solutions under ‘Both’. Maybe I’ll try the AWS bucket or DIY server solution. I guess I’d store the file name in a database on a server since I guess I would have to store usernames in a db on a server anyway in order for users to send files to each other. I guess the easiest way to interact with that remote database would be via POSTs using the corona networking library, correct? (to create the user accounts, store the filenames etc)

So in other words I would need to keep a database ‘in the cloud’ that all users of this app could create usernames on. I assume that’s how apps like instagram, facebook  words with friends, etc have usernames for account holders?

Thanks again!

oh thanks I see you posted more details too as I was typing up my first reply. Thank you!

If the ‘file’ is purely text, then forget about transferring it as a file.

Set up a server with PHP and MySQL, then write some basic scripts to handle user authentication, account creation, and reads/writes from the DB. 

You can simply write the ‘file text content’ to the DB.

@everyone,

If I’ve missed a drop dead easy solution please post.  I’m sure there are easier ways to do this than a DIY server, but at the cost of paying a 3rd party provider to host the server side of things and provide an API.

great idea. You’re right, in this case it doesn’t have to be a file, I guess I could just write the text to a database. I didn’t think of that. Good thought!  Eventually I think I’d want a way to transfer images, so in that case I might be back to files. But to start this might work out well.

Yes if anyone else has a solution we haven’t thought of please let us know!

Thanks again Roaming Gamer for your thoughtful replies

i have some firebase plugins that could help

https://scotth.tech/firebase

Firebase Database can store data

Firebase Storage can store files

Does firebase storage plugin work for others? If I initialise the bucket without timer.performWithDelay, then the app hangs in firebaseStorage.init().

And, if I initialise the bucket with timer.performWithDelay then the app doesn’t hang, but eventually nothing gets uploaded and upload listener will never get called back. Storage rules should be fine and allow read, write and authentication disabled. Also the file to be uploaded should be in system.DocumentsDirectory.

– Initialize

firebaseStorage = require “plugin.firebaseStorage”

timer.performWithDelay( 100, function() firebaseStorage.init() end)

– Upload

firebaseStorage.upload( system.pathForFile(“file.db”, system.DocumentsDirectory), “file.db”, function(e)

  print(“firebaseStorage.listener”) – this never gets called

  if (not e.error) then

        urlForFile = e.downloadURL

        native.showAlert( “Uploaded”,urlForFile, {“OK”} )

  else

        native.showAlert( “Error”,e.error, {“OK”} )

  end

end)

If you think there is a bug you should report it

https://goo.gl/forms/QjOJsFGghSEQqkJW2

Hi,

The next major update to Coronium Core will have a user management component which would make this a fairly simple process. All scripting is based in Lua, and just off the top of my head, I don’t think you would need to do any server-side coding when pairing the file transfer when using the user management component. This also allows you to transfer many different file types.

-dev

There are myriad ways to achieve this.

You didn’t say if this was for Android, iOS, or both.  I will assume you only want mobile solutions.

  • iOS Only
  • Both
    • AWS S3 Buckets  - https://marketplace.coronalabs.com/plugin/s3-lite
      • You’ll need an AWS account.  Then you will need to set up a bucket. 
      • Also, for this to work, the reader and writer both have to know the URL of the bucket and the name of the file.  How you will get this information to the receiver I don’t know, depending on how you want it to work.
    • DIY Server - Set up your own server running PHP.  Then, simply upload and download files via PUT and GET respectively using the corona networking library.
    • Corona Cloud - You’ll have to search for this, but it still exists and still works.  This will however be a lot for work to get set up initially.  Setting up the CC is easy, but you’ll have to write code to do this ‘file transfer’ thing and that is a lot of work.
    • Other marketplace solutions - Check it out there are probably other solutions: https://marketplace.coronalabs.com/ 

Note: At the end of the day, this is going to be real work (except for the iOS only solution.  That is easy.)

Note 2: Finding a provider is easy.  You’re just not thinking about the right kinds of providers.  I suggest Digital Ocean.

You left a lot of details out in your request for info, one key piece of info was the answer to this question:

“Is this shared file private between the two parties, or can any one with the app access the file?”  

If it is private, you are going to need to set up methods to:

  • Uniquely name the file when party A saves/sends it.
  • Asynchronously notify party B of the file name and the fact that the file has been written.
  • Download the file to party B’s device.

If it is not private, this implies to me that all apps are saving and reading the same file.  That seems unlikely.  However if that is the case, then you have to provide a means of dealing with the producer-consumer problem.

If however, you have a single producer and everyone else is consumer this becomes simple to coordinate.

Thanks SO much for the detailed and highly-organized reply!  This is very helpful. I’m actually mostly developing for Android. I’ll study your solutions under ‘Both’. Maybe I’ll try the AWS bucket or DIY server solution. I guess I’d store the file name in a database on a server since I guess I would have to store usernames in a db on a server anyway in order for users to send files to each other. I guess the easiest way to interact with that remote database would be via POSTs using the corona networking library, correct? (to create the user accounts, store the filenames etc)

So in other words I would need to keep a database ‘in the cloud’ that all users of this app could create usernames on. I assume that’s how apps like instagram, facebook  words with friends, etc have usernames for account holders?

Thanks again!

oh thanks I see you posted more details too as I was typing up my first reply. Thank you!

If the ‘file’ is purely text, then forget about transferring it as a file.

Set up a server with PHP and MySQL, then write some basic scripts to handle user authentication, account creation, and reads/writes from the DB. 

You can simply write the ‘file text content’ to the DB.

@everyone,

If I’ve missed a drop dead easy solution please post.  I’m sure there are easier ways to do this than a DIY server, but at the cost of paying a 3rd party provider to host the server side of things and provide an API.

great idea. You’re right, in this case it doesn’t have to be a file, I guess I could just write the text to a database. I didn’t think of that. Good thought!  Eventually I think I’d want a way to transfer images, so in that case I might be back to files. But to start this might work out well.

Yes if anyone else has a solution we haven’t thought of please let us know!

Thanks again Roaming Gamer for your thoughtful replies

i have some firebase plugins that could help

https://scotth.tech/firebase

Firebase Database can store data

Firebase Storage can store files