Page 1 of 2

Upload file, without log in

Posted: Wed Feb 04, 2015 2:58 pm
by Rui Song Chong

Hi,

I use link "http://devcenter.appery.io/tutorials/..." to try to let user upload image into the database file collection. It there a way to upload the image without the need to log in/out. I follow the tutorial and received this error "error:unauthorized". I believed it's because I do not have the log in/out features. Can I insert the user/password somewhere, so that I do not need to log in/out before I upload an image?
And also, I used this JavaScript code "uploadMultipleFilesHelper(uploadService, Apperyio('file_input'));" even though I only uploading one image, is there a problem?
Thanks for your help!


Upload file, without log in

Posted: Wed Feb 04, 2015 5:18 pm
by Alena Prykhodko

Hello,

[quote:]It there a way to upload the image without the need to log in/out.[/quote]
No, you need to create at least one user, and use its credentials for all users, but log in should be for security reason

[quote:]Can I insert the user/password somewhere, so that I do not need to log in/out before I upload an image?[/quote]
Yes, create a login in your app, and on page load event of your first page make login for your only one user, use token after login to make upload


Upload file, without log in

Posted: Wed Feb 04, 2015 6:15 pm
by Rui Song Chong

Hi,

Thanks for your respond, I can now upload images. But I have another question.
I want the user to be able to create a new row in the database, together with the image. How can I link the image file name uploaded accordingly into the database?
I tried to map in like this (image 1) in the "create service" "before send event" mapping, but it doesn't work. Please advise, thanks!

Image

Image


Upload file, without log in

Posted: Wed Feb 04, 2015 8:47 pm
by Alena Prykhodko

Do you mean to have reference between image and this row? In such case you can do it with pointer, see details http://devcenter.appery.io/documentat...


Upload file, without log in

Posted: Thu Feb 05, 2015 4:33 am
by Rui Song Chong

Hi,

But there isn't any option to link the pointer to the files collection, only to the user collection. Am I suppose to link it to the user collection if I'm using only one static user for all the uploads. Which means the user using this app do not need to log in to upload a file, the user and password is already static in the service.
In case my question was not clear, I want the information and files to be uploaded together into the table like the image below when the user click upload. Right now what I have is the information is uploaded into the table whereas the image is uploaded to the files collection. Thanks!

Image


Upload file, without log in

Posted: Thu Feb 05, 2015 11:46 am
by Evgene Karachevtsev

Rui,

1) Please upload a file to the DB first
2) Save _id
3) Upload info with saved _id


Upload file, without log in

Posted: Fri Feb 06, 2015 5:54 am
by Rui Song Chong

Hi,

I don't quite understand, do I have to create a pointer in the table to link it to the user collection first?
This is what I tried, right now I have a create_service and a upload service which would be invoked when I click the upload button, on the before event on create_servce, I map the user_id I stored when the user login, to the pointer user_id from the table. However, no information is uploaded to the table. Please advise, thanks!

Image


Upload file, without log in

Posted: Mon Feb 09, 2015 3:49 am
by Yurii Orishchuk

Hi Rui,

Here is a brief plan:

  1. Upload image.

  2. Get "fileName" of this image(on success event handler) and store it to some storage.

  3. In "create" service for your custom collection link "fileName" stored in storage(2nd step) to the "fileName" field.

    Details: http://prntscr.com/62ussm/direct

    Also it's not clear why do you want to link user(user_id) to this collection new item...

    Regards.


Upload file, without log in

Posted: Mon Feb 09, 2015 7:20 am
by Rui Song Chong

Hi,

How can I get the filename of the image I uploaded on the success event handler?
What should I put on the response tab of service_upload? Should I put it like this?

Image


Upload file, without log in

Posted: Mon Feb 09, 2015 4:35 pm
by Evgene Karachevtsev

Hello Rui,

Please add javascript code on success event:
preconsol.log(data.filename );/pre
Or add the same property to your service