怎样才能获得“幸福”呢?使用 Grails 的 Amazon S3 插件命名(通过 Jets3t)

发布于 2024-09-16 00:35:08 字数 843 浏览 10 评论 0原文

参考文献:

我所说的“快乐”名称是指我正在上传的文件的真实名称。 .. 例如,如果我要放置一个名为“foo.png”的文件,我希望该文件的 url 为 /foo.png。目前,我只是获取文件名的 GUID(没有文件扩展名)。

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

魔法唧唧 2024-09-23 00:35:08

您可以在S3Asset对象上设置关键字段来实现您的需要。

我将更新 doco 页面并提供更多相关信息。

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.

马蹄踏│碎落叶 2024-09-23 00:35:08

通过上传文件中给出的 lengthinputstreamfileName,您应该使用以下代码实现您想要的:

        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)

我希望它有所帮助。

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.

情何以堪。 2024-09-23 00:35:08

实际解决方案(由@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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文