这里的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对象上传文件
发布评论