Dirk Gissing
Posts: 0
Joined: Sat Oct 12, 2013 4:18 pm

send image from gallery

Hello,

In my app users have the option to upload a picture from their phone gallery to the app. This works and the image is shown in an element called "upload_image". Now I want the URL of this uploaded image to be sent with the other data. How do I retrieve the URL of the uploaded image?

I've tried "alert(Appery('image_upload').attr('src'));" but this shows a HUGE alert with the raw image source code, not the URL.

How do I do this?

Thank you!

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

send image from gallery

Hi Dirk,

You should pass a direct link to a file: http://devcenter.appery.io/documentat...

Uploade your image to Database beforehand: https://getsatisfaction.com/apperyio/...

Dirk Gissing
Posts: 0
Joined: Sat Oct 12, 2013 4:18 pm

send image from gallery

Thank you Katya, I will try this and update afterwords!

Dirk Gissing
Posts: 0
Joined: Sat Oct 12, 2013 4:18 pm

send image from gallery

I've tried the solution you provided "pass a direct link to a file". But I can't upload the base64 to the files collection. I keep getting "unauthorized" or "Cannot consume content type".

What should I do

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

send image from gallery

Hello Dirk,

You get unauthorized because you don't send session token to service.
You get "Cannot consume content type" probably because you send wrong header "Content-Type". For image you should send one of these:
http://en.wikipedia.org/wiki/Internet...

Dirk Gissing
Posts: 0
Joined: Sat Oct 12, 2013 4:18 pm

send image from gallery

I don't send session token because I don't have session token. Users don't have to login to upload a picture. I'm making a damage form for users so that they can send details of a damage and a picture. The app can be used without having to login.

Dirk Gissing
Posts: 0
Joined: Sat Oct 12, 2013 4:18 pm

send image from gallery

And about the "cannot consume content type": I only get that error when I try to use the files_upload_service. That service does not have the "Content-Type" header, and when I manually add that header parameter, it still doesn't work. In the other service "files_create_service" there is a parameter called "Content-Type" but over there I get the error of the session token.

Dirk Gissing
Posts: 0
Joined: Sat Oct 12, 2013 4:18 pm

send image from gallery

I can use the "files._create_service" now in the test environment and it works. A file is indeed uploaded, but when I try to download the jpeg file, it can't be opened. It's a corrupted JPEG file. The base64 data I retrieved from the photocamera, so it should be about right.

What is the problem here?

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

send image from gallery

Hello Dirk,

The base64 data is not jpeg file so you have message "it's a corrupted JPEG file"

Dirk Gissing
Posts: 0
Joined: Sat Oct 12, 2013 4:18 pm

send image from gallery

So how do I save a picture taken from the photogallery of the user to the files collection then??

Return to “Issues”