上传appEngine文件真的需要 [英] Upload file in appEngine really needed

查看:145
本文介绍了上传appEngine文件真的需要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始了一个项目,它是一个让世界听我所有个人歌曲的web应用程序。到目前为止,网站上提供的所有歌曲都存储在战争/歌曲中。然后,我的数据库只存储这个文件的路径,而且工作的非常好。

我想创建一个只能由管理员访问的网页(基本上是我:D)在这个位置上传我的歌曲,所以我不必部署整个项目只是为了添加一首歌曲......而我现在正在阅读,它在应用程序引擎中是不可能的?我不认为将歌曲存储在数据库中是一个好主意吗?

我可以为您解答我的问题吗?此外,如果应用引擎不适合我的目标,我想知道一些好的地方来托管我的Java应用程序......这似乎很罕见!

再次感谢。

解决方案

只需将您的文件存储在 Blobstore 中,而不是存储在文件系统中。而不是路径,你可以使用blob键。您可以像这样上传文件:

 < body> 
< form action =<%= blobstoreService.createUploadUrl(/ upload)%> method =postenctype =multipart / form-data>
< input type =filename =myFile>
< input type =submitvalue =提交>
< / form>




您可以在web.xml中设置约束来阻止访问您的网站: / p>

 < security-constraint> 
< web-resource-collection>
< url-pattern> / admin / *< / url-pattern>
< / web-resource-collection>
< auth-constraint>
<角色名称>管理员< /角色名称>
< / auth-constraint>
< / security-constraint>

然后从servlet提供文件:

  public void doGet(HttpServletRequest req,HttpServletResponse res)
throws IOException {
BlobKey blobKey = new BlobKey(req.getParameter(blob-key));
blobstoreService.serve(blobKey,res);


I've started a project, it's a web application to let the world listen all of my personnal songs. So far, all the songs available on the website are stored in war/songs. Then, my database only stores the path to this file and that works really nicely.

I wanted to created a web page only accessible to admin (basically me :D) to upload my songs at this location, so I don't have to deploy the entire project just to add a song ... And I am now reading that it's impossible in app engine ? I don't think storing the songs in the database is a good idea ?

Can I have you thoughts on my issue ? Thanks a lot !

Also, if app engine is not suited to my goal, I wanted to know some good place to host my java application ... that seems quite rare !

Thanks again ..

解决方案

It is possible on GAE. Simply you have to store your files in Blobstore, not in filesystem. Instead of path you could use blob key. You can upload your files like this:

<body>
<form action="<%= blobstoreService.createUploadUrl("/upload") %>" method="post" enctype="multipart/form-data">
    <input type="file" name="myFile">
    <input type="submit" value="Submit">
</form>

And you can set in web.xml constraint to prevent access to your site:

<security-constraint>
    <web-resource-collection>
        <url-pattern>/admin/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>admin</role-name>
    </auth-constraint>
</security-constraint>

And then to serve file from servlet:

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException {
    BlobKey blobKey = new BlobKey(req.getParameter("blob-key"));
    blobstoreService.serve(blobKey, res);

这篇关于上传appEngine文件真的需要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆