繁体   English   中英

有时会保存带有字节数组列的解析对象,但字节数组存储不正确

[英]Sometimes parse object with byte array column is saved but the byte array isn't saved properly

我正在使用此代码:

ParseObject newPObject = new ParseObject("animals");

newPObject.put("name", "dog");

newPObject.put("sound", soundAsByteArray);

try {

    newPObject.save();


} catch (ParseException e) {


}

98%的时间一切都保存得很好,我可以在解析数据浏览器中完美地获取文件,但是2%的时间我得到此错误:

<Error><Code> AccessDenied</Code> <Message>Access Denied</Message> <RequestId>****</RequestId> <HostId></HostId> </Error>

保存对象时没有任何异常,并且对象本身出现在数据浏览器中。

因此,在没有得到解析团队任何帮助的情况下,我决定将事情交到自己手中,这就是我所做的:

  1. 向对象添加了一个称为byteArrayLength的数字列
  2. 在云代码中使用以下代码定义了一个保存前功能:

     var animal = request.object; var bytesArrayLength = animal.get("byteArrayLength"); var sound = animal.get("sound"); Parse.Cloud.httpRequest({ url: sound.url(), success: function(fileResponse) { if (bytesArrayLength == fileResponse.buffer.length) { // Checked out - Continue with save response.success(); // Continue to the after save } else { // Something bad happened and we need to save the animal again response.error("Bytes length is not equals to the real length, need to re-upload sound"); } }, error: function(error) { response.error(error); } }); 
  3. 在客户端代码中,我捕获到异常并重试上传

奇迹般有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM