2016-07-07 117 views
0

我想超过32MB直接从AngularJSAngularJS直接上传到谷歌云存储错误

上传文件的大小更高GCS我能成功上传到Blobstore当文件大小小于使用下面给出的代码32MB。

$http.post(uploadUrl, $scope.formData, { 
    withCredentials: true, 
    headers: {'Content-Type': undefined}, 
    transformRequest: angular.identity 
}); 

当我尝试上传使用URL https://storage.googleapis.com/bucket-name/filename文件,我得到了下面的错误。

Credentials flag is 'true', but the 'Access-Control-Allow-Credentials' header is ''. It must be 'true' to allow credentials. Origin 'http://localhost:8080' is therefore not allowed access.

当我删除HTTP POST已使用标志withCredentials: true,我得到了响应,403,没有错误给出细节。

我已经设置了CORS提到的上传存储 [{"maxAgeSeconds": 3600, "method": ["GET", "POST", "HEAD"], "origin": ["http://localhost:8088"], "responseHeader": ["Content-Type"]}]

如何启用Access-Control-Allow-Credentials国旗在服务器?

回答

1

您可以在继续使用Blobstore的同时完成此操作,而不必切换到云存储。 Google文档处理得相当好。警告:这听起来像谷歌支持这是一个遗留功能,但建议使用可以存储,而不是。我个人并没有这样做,但听起来像Signed URLs可能是那里的答案。

如果您想继续使用blobstore,如我所知,Java中服务器端设置的说明是here。您应该在类似的网址找到与其他语言类似的说明。 :)

我最初不明白的一个棘手的部分:直接上传请求做它的事情,然后直接打电话给您的服务器与上传的信息,然后使用您的服务器的响应作为回应客户端。例如,您可以在服务器的上传处理程序中设置Access-Control-Allow-Origin标头,并将其添加到直接上载链接的响应中。

+0

嗨@Eric,谢谢你的回应。我尝试签署的网址,因为我有同样的错误。下载成功但不上传。对于通过blobstore上传,我得到了一个不同的错误,请参考http://stackoverflow.com/questions/38344261/gcs-heap-error-when-file-of-higher-size-was-uploaded。 我无法成功使用'Access-Control-Allow-Origin'标头,修改httpProvider默认标头'$ httpProvider.defaults.headers.common ['Access-Control-Allow-Origin'] ='*';'with'withCredentials :虚假设置没有太大帮助。你能指导我使用标题吗? – SetV

+0

您需要在_server_发送的_response_上设置该标头,而不是来自客户端的请求。因此,在您的Java代码中(我看到的是您链接的其他问题的选择语言),您可以使用'resp.setHeader(“Access-Control-Allow-Origin”,“*”);'。 –

+0

嗨@Eric,我可以坚持你的前两个解决方案。这真的有帮助! – SetV

相关问题