Page 1 of 1
Return filename after upload
Posted: Thu Sep 18, 2014 4:05 pm
by izozzy
I ma using the javascript in the file upload tutorial and that works well. My images are uploaded properly to the database in the Files collection.
My question is, after uploading the image, how do i return the stored filename. I need this as I want to use in a field in another collection.
For something like this, should I be using the javascript to upload the file?
Can you help?
Return filename after upload
Posted: Thu Sep 18, 2014 4:43 pm
by Evgene Karachevtsev
Hello Izozzy,
files_upload_service returns in response the name of the saved file in the form
code
{
"filename":<serverFileName>,
"fileurl":<url>
}
/code
You can get it on the success of the event service.
Return filename after upload
Posted: Fri Sep 19, 2014 6:47 am
by izozzy
I tried to put this javascript on the success of the event service,
alert(filename);
but it does not seem to work...
Return filename after upload
Posted: Fri Sep 19, 2014 8:37 am
by Maryna Brodina
Hello!
Change your code to prealert(data.filename);/pre data is an object which contains entire service response.
Return filename after upload
Posted: Fri Sep 19, 2014 8:41 am
by izozzy
I have just done what you have instructed, the alert window displays 'undefined' even though the file has successfully uploaded
Return filename after upload
Posted: Fri Sep 19, 2014 1:15 pm
by Maryna Brodina
I am sorry for misunderstanding. Service response has the following structure
so you need to use the following code prealert(data[0].success.filename);/pre
Return filename after upload
Posted: Fri Sep 19, 2014 2:13 pm
by izozzy
Return filename after upload
Posted: Mon Jul 13, 2015 7:26 am
by Nisa Khalid
hello izozzy,
how did you put file name to another collection?