SlickUpload
Welcome Guest Search | Active Topics | Log In | Register

How do I rename a file "before" uploading it? Options
imsam67
#1 Posted : Friday, November 25, 2011 6:03:38 PM
Rank: Member

Groups: Registered

Joined: 11/22/2011
Posts: 17
Location: Florida

I want to rename files before uploading them. I'd like to append a timestamp at the end of file names i.e.

myFile_YYYYmmddhhmmss.ext

so my file name would look like this: myFile_20111125180334.jpg

How do I handle this?


Thanks,
Sam
imsam67
#2 Posted : Friday, November 25, 2011 6:52:47 PM
Rank: Member

Groups: Registered

Joined: 11/22/2011
Posts: 17
Location: Florida

I'm uploading files to Amazon S3. I've used the fileNameMethod ="GuidWithExtension" for uploadStreamProvider in web.config but all files are still saved using ClientName(s).

Here's what my web.config entry looks like for uploadStreamProvider:

<uploadStreamProvider type="S3" accessKeyId="myS3AccessId" secretAccessKey="mySecretAccessKeyForS3" bucketName="myS3BucketName" fileNameMethod ="GuidWithExtension" />

What am I doing wrong?


Thanks,
Sam
imsam67
#3 Posted : Friday, November 25, 2011 8:31:57 PM
Rank: Member

Groups: Registered

Joined: 11/22/2011
Posts: 17
Location: Florida

Uploading to S3, I can't get it to rename files. With the current settings, it's overwriting the file with identical name.


Thanks,
Sam
Axosoft
#4 Posted : Monday, November 28, 2011 10:40:10 AM
Rank: Administration


Groups: Administrators

Joined: 7/7/2005
Posts: 1,586
Location: Scottsdale, AZ

Did you want to do the timestamp or the guid? The problem with the Guid configuration was a documentation issue. It should be "objectNameMethod" (which is only used for the S3 provider) rather than "fileNameMethod" (which is only used for the File provider).

If you want to do the timestamp, you'll need to create your own custom upload stream provider class. It would inherit from S3UploadStreamProvider and override the GetObjectName method. That will allow you to control what key is used to store the file on S3. Something like this:

public class CustomS3UploadStreamProvider : S3UploadStreamProvider
{
        public CustomS3UploadStreamProvider(UploadStreamProviderElement settings)
            : base(settings)
{ }

        public override string GetObjectName(UploadedFile file)
        {
// TODO: return the name you want here
}
}

Then, configurare that provider in the web.config by setting the type attribute to (replacing with whatever names you use):

type="YourNamespace.YourClassName, YourAssemblyName"

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.