使用Google云端存储HTML表单的POST / PUT对象上传文件

编程入门 行业动态 更新时间:2024-10-25 10:25:56
本文介绍了使用Google云端存储HTML表单的POST / PUT对象上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在用Eclipse的Google-App-Engine Plugin开发一个非常简单的Web应用程序。 我刚刚在我的home.html的HTML中编写了这段代码。

这里的home.html是:

<!DOCTYPE html PUBLIC - // W3C // DTD HTML 4.01 Transitional // ENwww.w3/ TR / HTML4 / loose.dtd> < html> < head> < meta http-equiv =Content-Typecontent =text / html; charset = US-ASCII> < title>在此插入标题< / title> < / head> < body> < form action =storage.googleapis/myBucketNamemethod =postname =putFileid =putFile enctype =multipart / form-data > < input type =hiddenname =keyvalue =我不知道这里会发生什么,因为我无法猜测我要上传哪个文件/> < input type =hiddenname =success_action_statusvalue =201/> < input type =filename =fileid =file> < input type =submitvalue =上传> < / form> < / body> < / html>

这是一个非常简单的表单,没有任何形式的授权, ,您可以看到: developers.google/storage/ docs / reference-methods#postobject (我已经记住了)。 $ b 我有不同的来自Google(XML格式)的响应错误:

<错误> <代码> InvalidArgument< / Code> < Message>无效参数< / Message> <详细>缺少文件部分< /详细> < / Error>

<错误> <代码> InvalidArgument< / Code> < Message>无效参数< / Message> <详细信息>无法使用POST创建桶。< / Details> < / Error>

<错误> <代码> InvalidArgument< / Code> < Message>无效参数< / Message> <详情> 无效的查询参数:[file,success_action_status,key] < / Details> < / Error>

任何人都可以帮我填写这张表格吗?

具体来说:它适用于这种形式:

< form action = storage.googleapis/bucketNamemethod =postname =putFileid =putFile enctype =multipart / form-data> < input type =hiddenname =bucketvalue =bucketName> < input type =hiddenname =keyvalue =fileUploadingName/> < input type =hiddenname =success_action_statusvalue =201/> < input type =filename =file> < input type =submitvalue =上传> < / form>

fileUploadingName是例如:sample.txt

但问题依然存在,因为我需要弄清正确的密钥,即我要上传的文件的名称。

解决方案

这是一个工作表单的例子:

< form action =storage.googleapis/bucketName method =postenctype =multipart / form-data> < input type =hiddenname =keyvalue =$ {filename}/> < input type =hiddenname =success_action_statusvalue =201/> < input type =filename =file> < input type =submitvalue =上传> < / form>

请注意,没有隐藏存储桶字段,因为存储桶名称已经包含在表单POST URL中。

关键参数可以是 $ {filename} which将采取正在上传的文件的原始名称。但是,如果您尝试上传两个同名的文件,则会被另一个文件覆盖。

另外,不要忘记您的存储桶需要具有PUBLIC_WRITE ACL。你可以用gsutil来设置它,例如:

gsutil acl set public-read-write gs:// bucketName

I'm developing a VERY simple Web-App with Google-App-Engine Plugin for Eclipse. I've just written this snippet of code in HTML of my "home.html".

Here home.html is:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> <title>Insert title here</title> </head> <body> <form action="storage.googleapis/myBucketName" method="post" name="putFile" id="putFile" enctype="multipart/form-data"> <input type="hidden" name="key" value="I don't know what is going here because i cannot guess which file i will upload" /> <input type="hidden" name="success_action_status" value="201" /> <input type="file" name="file" id="file"> <input type="submit" value="Upload"> </form> </body> </html>

This is a very simple Form without any kind of Authorization or whatever.. For Info, you could see this: developers.google/storage/docs/reference-methods#postobject (that i've already memorized).

I have had different Response Error from Google (in XML Format) like:

1)

<Error> <Code>InvalidArgument</Code> <Message>Invalid argument.</Message> <Details>Missing file part</Details> </Error>

2)

<Error> <Code>InvalidArgument</Code> <Message>Invalid argument.</Message> <Details>Cannot create buckets using a POST.</Details> </Error>

3)

<Error> <Code>InvalidArgument</Code> <Message>Invalid argument.</Message> <Details> Invalid query parameter(s): [file, success_action_status, key] </Details> </Error>

Can anyone help me to fill in this form, please?

To be more specific: It works with this form:

<form action="storage.googleapis/bucketName" method="post" name="putFile" id="putFile" enctype="multipart/form-data"> <input type="hidden" name="bucket" value="bucketName"> <input type="hidden" name="key" value="fileUploadingName" /> <input type="hidden" name="success_action_status" value="201" /> <input type="file" name="file"> <input type="submit" value="Upload"> </form>

The fileUploadingName is for example: sample.txt

but the problem persists because i need to fiil the correct "key" that is the name of the file that i'm going to Upload. How can i fix it?

解决方案

Here's a working form example:

<form action="storage.googleapis/bucketName" method="post" enctype="multipart/form-data"> <input type="hidden" name="key" value="${filename}" /> <input type="hidden" name="success_action_status" value="201" /> <input type="file" name="file"> <input type="submit" value="Upload"> </form>

Note that there's no hidden bucket field as the bucket name is already included in the form POST URL.

The key parameter can be ${filename} which will take the original name of the file being uploaded. Though if you try to upload two files with the same name one will get overwritten by the other.

Also, don't forget that your bucket needs to have PUBLIC_WRITE acl. You can set it with gsutil, e.g.:

gsutil acl set public-read-write gs://bucketName

更多推荐

使用Google云端存储HTML表单的POST / PUT对象上传文件

本文发布于:2023-10-29 10:26:33,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:云端   表单   上传文件   对象   Google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!