Git Product home page Git Product logo

Comments (8)

godblesshugh avatar godblesshugh commented on June 2, 2024

并发保存的问题。在 LC 的 iOS 客户端也碰到了这个问题。

from leantodo-weapp.

leeyeh avatar leeyeh commented on June 2, 2024

tempObjects 是什么?文件还是对象?

看起来你想批量保存一批对象,然后其中一个失败了(Document not found),整个 Promise 就失败了。

这是符合预期的啊,你需要 debug 下哪个对象是不存在的。

另外,AV.Object.saveAll 可以用在一个请求里批量保存对象,会更可靠(但是在这个 case 里肯定还是会 Document not found 失败)。

另外,你确定这个问题是 leantodo-weapp 的问题?

from leantodo-weapp.

godblesshugh avatar godblesshugh commented on June 2, 2024

是一个文件。其实我的源码是类似这样的:

function saveAll(tempFilePaths) {
    var promises = [];
    for (var i = 0; i < tempFilePaths.length; i++) {
        promises.push(savePhoto(tempFilePaths[i]));
    }
    return AV.Promise.all(promises);
}

function savePhoto(tempFilePath) {
    var photo = new Photo();
    photo.set('photoFile', new AV.File('wxapp', {
        blob: {
            uri: tempFilePath
        },
    }));
    return photo.save();
}

然后,调用方式是这样的:

saveAll(tempFilePaths).then(null, function(err){
    // 错误处理
}).then(function(){
    // 不管成功失败,都刷新一下
    refresh();
});

因为这个 refresh() 始终没有被调用,所以才说是可能没有超时的处理。

from leantodo-weapp.

godblesshugh avatar godblesshugh commented on June 2, 2024

然后我把 saveAll 去掉了,改成 reduce 的方式,强制改成顺序上传是可行的:

tempFilePaths.reduce(function(promise, tempFilePath) {
    return promise.then(function() {
        return savePhoto(tempFilePath);
    });
}, AV.Promise.resolve(true)).catch(function(err) {
    // 错误处理
}).then(function() {
    // 不管成功失败,都刷新一下
    refresh();
})

from leantodo-weapp.

leeyeh avatar leeyeh commented on June 2, 2024

如果是并发上传的话,小程序有个同事 5 个请求的上线,可以看下控制台有没有类似的异常。我不确定这个异常是否会被正确 catch 到,我需要试一下。

from leantodo-weapp.

godblesshugh avatar godblesshugh commented on June 2, 2024

OK,我这边是选择了两张图片同时做上传出现的。是在移动端出现,但是在小程序的那个 IDE 里面没有。
而且没有发现类似的异常,我的移动端是能一直重现的,改成 reduce 的时候倒是一切正常了。

from leantodo-weapp.

leeyeh avatar leeyeh commented on June 2, 2024

论坛也有类似的多图上传失败的报告,我调查一下:

https://forum.leancloud.cn/t/topic/12790

from leantodo-weapp.

leeyeh avatar leeyeh commented on June 2, 2024

Android 真机不支持并发上传图片。详情与解决方案参见上面的论坛帖子。

from leantodo-weapp.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.