Rui Song Chong
Posts: 0
Joined: Sat Jan 17, 2015 10:51 am

Upload file, without log in

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!

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Upload file, without log in

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

Rui Song Chong
Posts: 0
Joined: Sat Jan 17, 2015 10:51 am

Upload file, without log in

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

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Upload file, without log in

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...

Rui Song Chong
Posts: 0
Joined: Sat Jan 17, 2015 10:51 am

Upload file, without log in

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

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Upload file, without log in

Rui,

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

Rui Song Chong
Posts: 0
Joined: Sat Jan 17, 2015 10:51 am

Upload file, without log in

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

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Upload file, without log in

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.

Rui Song Chong
Posts: 0
Joined: Sat Jan 17, 2015 10:51 am

Upload file, without log in

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

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Upload file, without log in

Hello Rui,

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

Return to “Issues”