How to add custom "File Name" to an image/file being uploaded?

This forum contains topics that were moved from Get Satisfaction
xman
Posts: 0
Joined: Sun Jul 06, 2014 7:05 pm

How to add custom "File Name" to an image/file being uploaded?

Post by xman »

I am using the following tutorial to upload images to "Files" pre defined collection.
http://devcenter.appery.io/tutorials/...

My design requirement is that I need to automatically update the file name to something with a specific tag. I've tried to modify the request of the db__file_upload_service and added "File Name" parameter. Then I've added a JS to the "File Name" parameter in request"

return 'foo_bar_';

The file/images are getting successfully uploaded, however, the name is never what I want (but is some default file name code that Appery uses).

How can I add a custom name to file while it's being uploaded?

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

How to add custom "File Name" to an image/file being uploaded?

Post by Kateryna Grynko »

Hello,

File name specified when uploading to Database is available in a field "Original File Name" in Files collection.

xman
Posts: 0
Joined: Sun Jul 06, 2014 7:05 pm

How to add custom "File Name" to an image/file being uploaded?

Post by xman »

Hi Katya,

I know that the name of the file being uploaded gets stored in "Original File Name", that is not an issue. These files will be uploaded by users, and I don't expect them to add a consistent tag to file name. I want to add a custom identity suffix automatically under the hood to the file being uploaded for future indexing. That is the issue.

The file database today has no ability to add a new Column so I don't have any other way. There 2 name columns available today:

  • File Name

  • Original File Name

    But I'm not able to change the name of the file being uploaded. For example assume that I want to change the file name from:

    foobar.txt

    • to -
      foobar_username.txt

    ...and want to do this automatically under the hood. I see that db__file_upload service (on import) does not have any Name parameter in request. So I added "File Name" parameter manually to the Request parameters list. I store username into LSV on login and have mapped that to "File Name". However this does not work, the name of the file is still in default Appery format and not what I want it to be.

xman
Posts: 0
Joined: Sun Jul 06, 2014 7:05 pm

How to add custom "File Name" to an image/file being uploaded?

Post by xman »

Any thoughts Appery experts?

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

How to add custom "File Name" to an image/file being uploaded?

Post by Evgene Karachevtsev »

Hello Xman,

To upload file, send POST request to according URL:
precurl -X POST \
-H "X-Appery-Database-Id: " \
-H "X-Appery-Session-Token: " \
-H "Content-Type: " \
-d "" \
https://api.appery.io/rest/1/db/files/

where: is Appery DB user's session token;
is database unique identifier;
is the name of file in DB;
is MIME content type;
is the contents of file;

Server returns HTTP 201 Created status and JSON object response (with "Location:" header):
{
"filename":,
"fileurl":
}/pre

xman
Posts: 0
Joined: Sun Jul 06, 2014 7:05 pm

How to add custom "File Name" to an image/file being uploaded?

Post by xman »

Hi Evgene,

I have already created the service via:

Create New - Database Services
...and selected _files to import service. This creates the following service for me:

myDBName__files_upload_service

This service Request format already has the following:

(1.) X-Appery-Database-Id (set to {database_id})
(2.) X-Appery-Session-Token (I've mapped user session token to it)
(3.) data

I've run this service and uploaded files successfully. Now, my problem is how do I use this same service to add the naming structure that I want to the "Files" pre-defined collections column named "File Name".

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

How to add custom "File Name" to an image/file being uploaded?

Post by Evgene Karachevtsev »

Sorry, there was a mistake in my last reply:

code
curl -X POST \
-H "X-Appery-Database-Id: <databaseID>" \
-H "X-Appery-Session-Token: <userSessionToken>" \
-H "Content-Type: <contentType>" \
-d "<fileContent>" \
https:&#47;&#47;api&#46;appery&#46;io/rest/1/db/files/<fileName>

where: <userSessionToken> is Appery DB user's session token;
<databaseID> is database unique identifier;
<fileName> is the name of file in DB;
<contentType> is MIME content type;
<fileContent> is the contents of file;

Server returns HTTP 201 Created status and JSON object response (with "Location:<url>" header):
{
"filename":<serverFileName>,
"fileurl":<url>
} /code

xman
Posts: 0
Joined: Sun Jul 06, 2014 7:05 pm

How to add custom "File Name" to an image/file being uploaded?

Post by xman »

Evgene, sorry I don't understand what I'm missing.

Here is my mapping: http://awesomescreenshot.com/01337hz764

fileName parameter is what I added manually to the file upload service.

When I load the file, the service runs fine and uploads the file. But the "File Name" column in DB still reads a default name as like here:

http://awesomescreenshot.com/01337hzy76

So what and where I need a fix?

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

How to add custom "File Name" to an image/file being uploaded?

Post by Yurii Orishchuk »

Hi Xman,

Unfortunately you can not change this column(File name) in Files collection.

This value is unique within this Files collection and generates by system.

See details: http://prntscr.com/462tsm/direct

Also if you want to change "Original filename" and thus - part of "File name" you can change your service(which is you have automaticaly imported) with way described by Evgene above.

Regards.

xman
Posts: 0
Joined: Sun Jul 06, 2014 7:05 pm

How to add custom "File Name" to an image/file being uploaded?

Post by xman »

Yurii, sure if I can change "Original File Name" that will work too.

However, I'm still confused how exactly will I have to modify my imported service? What field do I exactly change? I've added "where" parameter to it, and add JS

return '{"Original File Name":"'+value+'"}';

where "value" is coming from mapping. But it still does not work.

Post Reply