Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

I am uploading an image to the files collection

I am uploading an image to the files collection

and after it is uploaded, I wish the page to refresh showing the uploaded image. I have the following js:

preconsole.log('data[0] = ',data[0]);
console.log('image filename = ',data[0].success.filename);
//set image on page
Apperyio('news_image').val(data[0].success.fileurl);
console.log('news_image = ',Apperyio('news_image').val());
//save filename to storage
Apperyio.storage.news.update("$['newsImageName']", data[0].success.filename); /pre

What i wish to know is The line:
codeApperyio('news_image').val(data[0].success.fileurl);/code

Is val the correct method for updating the image url and if so how can I refresh the page to show the changes?

Egor Kotov6832188
Posts: 0
Joined: Wed Nov 19, 2014 5:15 pm

I am uploading an image to the files collection

Hello Terry,

Unfortunately, you need to specify url to the image instead of name
Here is a curl rule to generate url to your image file uploaded to DB.
curl -X GET \
https://api.appery.io/rest/1/db/files...\
[?][encoded="base64"][&][sessionToken=]\
[&][masterKey=]

But if you had your url generated, then you will not being able to set it right,cause once you triggered Success event for Create file service your data object has different structure:
data.filename

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

I am uploading an image to the files collection

The output from my console shows that both the image name AND the image url are passed in the success event via the data object array:

predata[0] = Object {success: Object}success: Object
filename: "9c3e520b-8d03-4bf9-b3c5-d67d7566ba3a.ebay.png"
fileurl: "https://api.appery.io/rest/1/db/files/5422ac3ee4b0b7fdcc760e31/9c3e520b-8d03-4bf9-b3c5-d67d7566ba3a.ebay.png"
proto: Object
proto: Object

image filename = 9c3e520b-8d03-4bf9-b3c5-d67d7566ba3a.ebay.png
news_image = https://api.appery.io/rest/1/db/files/5422ac3ee4b0b7fdcc760e31/9c3e520b-8d03-4bf9-b3c5-d67d7566ba3a.ebay.png/pre

since I have the url, then surely all I need to do is assign it to my image component with something like:

pre//set image on page
Apperyio('news_image').val(data[0].success.fileurl);
console.log('news_image = ',Apperyio('news_image').val());/pre

which is what I have done, but the image is not being shown.

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

I am uploading an image to the files collection

I am beginning to think that '.val()' is wrong after studying the source.

I suspect I need to access the .src property, so I tried this...

pre//success data
console.log('data[0] = ',data[0]);

//filename & url
console.log('image filename = ',data[0].success.filename);
console.log('image URL = ', data[0].success.fileurl);

//fileurl
$("img[name='news_image']").src = data[0].success.fileurl;
console.log('news_image = ', $("img[name='news_image']").src);/pre

Unfortunately, this doesn't work either

FYO: the source looks like this:

pre <!-- news_image -->
<Image id="CreateNewsItem_news_image"
dsid="news_image" name="news_image" />
/pre

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

I am uploading an image to the files collection

fixed it. the solution is as follows:

pre&#47;&#47;fileurl
$("img[name='news_image']")&#46;attr('src', data[0]&#46;success&#46;fileurl);
console&#46;log('news_image = ', $("img[name='news_image']")&#46;attr('src'));
/pre

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

I am uploading an image to the files collection

Great! Thank you for getting back.

Todd Penny
Posts: 0
Joined: Sun Jan 12, 2014 4:29 pm

I am uploading an image to the files collection

Thanks for posting this. I need to set an image in my app based a url created by my app. Can you tell me the syntax to simply set the image resource to a URL (not hosted by appery)?

Return to “Issues”