【发布时间】:2016-07-07 13:43:03
【问题描述】:
我正在尝试将 Processing 中的图片上传到 Google Cloud Storage,但是当我查看存储空间时,我只有一张空白图片。
我正在使用“HTTP 请求处理”库来上传图像。
这是以下代码(已更新):
import http.requests.*;
int number = 0;
void setup(){
size(640,480);
}
void draw() {
if(number < 1) {
PostRequest post = new PostRequest("https://www.googleapis.com/upload/storage/v1/b/hs_test01/o?uploadType=media&name=person0.jpg&access_token=ya29.Ci8aA6-n96angt2d9mIyDUL2_4bHP5ybP-5deHb3zbnpbwFgwAGD5vx2LlydFwCjBA");
File f = new File(sketchPath("data/test.jpg"));
post.addFile("image/jpeg", f);
long size = f.length();
println(size);
post.addHeader("Content-Type","image/jpeg");
post.addHeader("Content-Length","163155");
post.send();
println("Reponse Content: " + post.getContent());
println("Reponse Content-Length Header: " + post.getHeader("Content-Length"));
}
number++;
}
来自 API 的响应:
Reponse Content: {
"kind": "storage#object",
"id": "hs_test01/person0.jpg/1468064800417000",
"selfLink": "https://www.googleapis.com/storage/v1/b/hs_test01/o/person0.jpg",
"name": "person0.jpg",
"bucket": "hs_test01",
"generation": "1468064800417000",
"metageneration": "1",
"contentType": "image/jpeg",
"timeCreated": "2016-07-09T11:46:40.413Z",
"updated": "2016-07-09T11:46:40.413Z",
"storageClass": "STANDARD",
"size": "1101980",
"md5Hash": "msH3vhzgwNKPd5aRXfy/vA==",
"mediaLink": "https://www.googleapis.com/download/storage/v1/b/hs_test01/o/person0.jpg?generation=1468064800417000&alt=media",
"crc32c": "nGKW7A==",
"etag": "COjJvsen5s0CEAE="
}
这是我到目前为止所遵循的教程:https://cloud.google.com/storage/docs/json_api/v1/how-tos/simple-upload#sending_a_simple_upload_request
还有一个提示,我必须给出图片的内容长度(它的字节数)。可能是因为这个我在存储中只收到了一个空白图像吗?如果是,我怎样才能自动读取图像的字节? The result of the uploaded pic so far
【问题讨论】:
-
我无法重现此问题。您确定此白色图像的原因了吗?下面提供的任何答案对此有帮助吗?
-
@Nicholas 抱歉,没有看到您的评论。不,很遗憾,我转而使用 Python 并使用 Google 的 gsutil 工具,然后就可以了。
标签: processing google-cloud-storage google-cloud-endpoints google-cloud-platform