Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oss sts回调后端返回的json数据, 前端解析失败 #420

Closed
zzzzzga opened this issue Apr 3, 2018 · 4 comments
Closed

oss sts回调后端返回的json数据, 前端解析失败 #420

zzzzzga opened this issue Apr 3, 2018 · 4 comments

Comments

@zzzzzga
Copy link

zzzzzga commented Apr 3, 2018

stream-http/response.js
case 'arraybuffer':
if (xhr.readyState !== rStates.DONE || !xhr.response)
break
response = xhr.response
self.push(new Buffer(new Uint8Array(response)))
break
new Uint8Array(response) 该方法不能解析json字符串

@PeterRao
Copy link
Collaborator

PeterRao commented Apr 3, 2018

提供下具体调用代码

@zzzzzga
Copy link
Author

zzzzzga commented Apr 4, 2018

let options = {
accessKeyId: stsTokenData.AccessKeyId,
accessKeySecret: stsTokenData.AccessKeySecret,
stsToken: stsTokenData.SecurityToken,
bucket: stsTokenData.BucketName,
endpoint: stsTokenData.EndPointName,
region: stsTokenData.RegionName,
secure: stsTokenData.IsHttps,
dataType: 'json',
callback: {
url: stsTokenData.CallBackInfo.Url,
body: stsTokenData.CallBackInfo.Body,
contentType: stsTokenData.CallBackInfo.ContentType,
customValue: stsTokenData.CallBackInfo.CustomValue
}
client.multipartUpload(filename, file, options).then((results) => {
// 上传完成

console.log(uploadInfo) 

}).catch((err) => {
console.log(err)
return Promise.reject(err)
})

在options中配置回调地址,上传就不成功,发现的原因是 :无法解析从回调地址返回的json

@zzzzzga
Copy link
Author

zzzzzga commented Apr 4, 2018

stream-http 2.8以后才有问题,2.7没有问题

@binghaiwang
Copy link
Contributor

binghaiwang commented Apr 6, 2018

我们测试case中的 callback服务器返回的都是json的数据的

//这是python服务器的片段代码,返回的数据
resp_body = '{"Status":"OK"}'
        self.send_response(200)
        self.send_header('Content-Type', 'application/json')
        self.send_header('Content-Length', str(len(resp_body)))
        self.end_headers()
        self.wfile.write(resp_body)

callback 里边的传入数据能否具体一点 比如stsTokenData.CallBackInfo.ContentType 这个是什么, 并提供下你的x-oss-request-id

accessKeyId: stsTokenData.AccessKeyId,
accessKeySecret: stsTokenData.AccessKeySecret,
stsToken: stsTokenData.SecurityToken,
bucket: stsTokenData.BucketName,
endpoint: stsTokenData.EndPointName,
region: stsTokenData.RegionName,
secure: stsTokenData.IsHttps,

这些 都是初始化clent需要的, 调用multipart不需要的, dataType: 'json' 这个你用来干啥的,文档没有这个参数

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants