Unable to Rename File when using App Connect S3 Upload

I can successfully rename and upload a file to my S3 bucket, but only when I manually enter the filename.

If I try using a filename previously saved in a session, it doesn’t upload.

I have made sure the session value exists before uploading:

So I’m wondering if it might have something to do with the way the session is referenced in the server actions?

In my experience, there’s no issue with how the $SESSION variables are accessed in server connects. In a NodeJS environment. Are those quotes “” part of the session variable name ??

Yes, the quotes around the session variable are just how my browser’s web inspector displays it. I use Safari, but it’s the same for Chrome.

So I have ditched the idea of using a session variable, but I really don’t know which input I can use as my key. Using the $_GET variable ‘name’ correctly uploads the initial file name, but I want to change this to something more controllable.

Unfortunately the tutorial for using this uploader is quite basic and doesn’t cover what I need. If anyone knows any tricks I can use, it would be welcome. Thanks.

The session on the client is different from the session on the server. The session value you are showing in the dev console is not available to the s3 action in the server.

Thanks Ken. So setting a session on the server would be available to use with S3?

I was thinking that since the original name of the file is uploaded via $_GET, I could use the same idea for another variable eg. ‘new_filename’. However, I’m not sure where the best place to define this is.

Correct, if you use the set session action on the server, that will be available to all server actions including s3.

1 Like

Now that I realise there’s a difference between browser and server side sessions (I’m sure I’m not the first person confused by this nomenclature), I’m starting to wonder if I can actually achieve my objective.

Sure, I’ve been able to set a session variable on the server. And this does work with S3. However the value I want to use is accessed in the App Connect panel and I can’t find any references which match the current interface about overriding a server side session variable in App Connect.

So my question is this. Has anyone been able to change the name of files they upload to an S3 bucket? If so, how did you achieve this? Thanks in advance.

(I’m sure I’m not the first person confused by this nomenclature.)

Definitely include me in that group!

You can use any dynamic data you would like in naming the file. If the name is provided by the user, then your GET variable is an option, or you can use a form to POST data to the server.

Thanks Ken. I’ll see how I go!
Peter

Hi all.

Unfortunately I am yet to find a workable solution - I’m sure I’m missing something obvious! To reiterate, I am simply trying to change the name of the uploaded file before it gets sent to my S3 bucket. I initially tried to use a session, but have now tried using a GET variable.

Here is the code for the S3 Uploader:

And here are my S3 Sign Properties:

So when I use ‘$_GET.name’ in the key path, it uploads the current filename. So it should follow that I can use a different GET variable - in this case ‘$_GET.filenamenew’. However, I don’t know how or where to define this. Traditionally I would add a ‘?filenamenew="xyz.jpg’ to the url, but I am unsure how to insert a GET variable inside the JSON of the sign upload_categories.php file.

Hoping someone can offer some further guidance because there are no references to this in the tutorials.

Cheers,
Pete

Hi Pete,
Had exactly the same outcome with node.js,
As it seems s3 upload defaults to overwriting an existing file with the same name,
being able to rename the file would be very helpful…Sorry I can’t help :frowning:

Thanks Jim.

FYI I was able to resolve the problem by using the old file upload method - where the file is uploaded to the server first, before transferring to the bucket. This method has provision to rename the file.

If only the new method included the same functionality…

Cheers.

I realize you made a work around.

In case anyone else is dealing with this, I was able to change the filename using the following method:

  1. Custom PHP API.
  2. Set a Wappler Value to the data of that API
  3. Set the "key" field to that Wappler Value.

MORE DETAILS:
I made my own PHP api that sends me a random number (but this could be anything, even a value or form field that your user just submitted and this PHP file grabs it). Using the API I get the data.
For my case the php file basically says:

<?php echo rand(10000,99999); ?>

Then I "Set Value" on that data and assign it to the "RandomNumber" value.

Then, in the "Key" field of the S3 upload I utilize that value.
As you can see below, I actually use another value called "FileNameSetter" because in that value I hash the file name with a sha256, add a timestamp, and then a five digit random number.

Am I a little obsessed about having unique file names? Yes. That's okay :joy:

But, it does work.

image