sintaxi / dbox

NodeJS SDK for Dropbox API (THIS LIBRARY IS OBSOLETE!!)
513 stars 91 forks source link

Uploading Microsoft documents #81

Open akaramires opened 10 years ago

akaramires commented 10 years ago

Here is my code

var downloadUrl, fileTitle;

                        downloadUrl = transfers[i].downloadUrl;
                        fileTitle = transfers[i].title;

                        var upload_id = null,
                            offset = 0,
                            options = {
                                'url'    : downloadUrl,
                                'headers': {
                                    'Authorization': 'Bearer ' + req.user.google.access_token
                                }
                            };

                        var requestGet = request.get(options);

                            requestGet
                                .on('data', function (chunk) {
                                    console.log('on data');
                                    var params = {};

                                    if (offset > 0) {
                                        params.offset = offset;
                                    }

                                    if (upload_id !== null) {
                                        params.upload_id = upload_id;
                                    }

                                    requestGet.pause();
                                    client.chunk(chunk, params, function (status, reply) {
                                        if (upload_id === null) {
                                            upload_id = reply.upload_id;
                                        }

                                        offset = reply.offset;
                                        console.log(upload_id, (offset / 1024 / 1024).toFixed(2) + ' mb');
                                        requestGet.resume();
                                    });
                                })
                                .on('end', function () {
                                    client.commit_chunks(fileTitle, {
                                        upload_id: upload_id,
                                        overwrite: false
                                    }, function (status, reply) {
                                        console.log('File was uploaded', status, reply);
                                    });
                                })
                                .on("error", function (err) {
                                    console.log('error', error);
                                });

After uploading I get a broken file (screen 1, screen 2)

This problem only with Microsoft documents