views:

31

answers:

3

References:

By "happy" names, I mean the real name of the file I'm uploading... for instance, if I'm putting a file called "foo.png" I'd expect the url to the file to be /foo.png. Currently, I'm just getting what appears to be a GUID (with no file extension) for the file name.

Any ideas?

A: 

With length, inputstream and fileName given from the uploaded file, you should achieve what you want with the following code :

        S3Service s3Service = new RestS3Service(new AWSCredentials(accessKey, secretKey))
        S3Object up = new S3Object(s3Service.getBucket("myBucketName"), fileName)
        up.setAcl AccessControlList.REST_CANNED_PUBLIC_READ
        up.setContentLength length
        up.setContentType "image/jpeg"
        up.setDataInputStream inputstream
        up = s3Service.putObject(bucket, up)

I hope it helps.

fabien7474
+1  A: 

You can set the key field on the S3Asset object to achieve what you need.

I'll update the doco page with more information on this.

leebutts
Sweet, that did it!
longda
A: 

Actual solution (as provided by @leebutts):

import java.io.*;
import org.grails.s3.*;

def s3AssetService;
def file = new File("foo.png"); //assuming this file exists     
def asset = new S3Asset(file);
asset.mimeType = extension;
asset.key = "foo.png"
s3AssetService.put(asset);
longda