question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Files get corrupted when uploading

See original GitHub issue

Files get corrupted when I upload a doc, docx or pdf file:

dbx.filesUpload({ path:  path, contents: fs.readFileSync(filepath) })
    .then(function (response) {
        console.log(response);
    })
    .catch(function (err) {
        console.log("Error:");
        console.log(err);
    });

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
smarxcommented, Sep 17, 2016

@ThomasBormans, drop the 'utf8' from your call to fs.readFile. Zip files are not UTF-8 encoded.

0reactions
ThomasBormanscommented, Sep 17, 2016

I have the same problem. I have a zip file and the following code:

var fs = require('fs');
var path = require('path');
var Dropbox = require('dropbox');
var dbx = new Dropbox({
    accessToken: 'my_access_token'
});

fs.readFile(path.join(__dirname, '/test.zip'), 'utf8', function(err, contents) {
    var options = {
        path: '/test.zip',
        contents: contents
    };
    dbx.filesUpload(options)
        .then(function(response) {
            console.log(response);
        })
        .catch(function(err) {
            console.log(err);
        });
});

When the file is uploaded, it automatically downloads on my computer (through the Dropbox app for Mac) in my root folder of Dropbox. When I try to unzip the uploaded file, I get the following message: `Unable to expand “test.zip” into “Dropbox”. (Error 21 - Is a directory.).

This is the output from the Dropbox sdk:

{
  name: 'test.zip',
  path_lower: '/test.zip',
  path_display: '/test.zip',
  id: 'id:qMqpuUbnx70AAAAAAApQWg',
  client_modified: '2016-09-17T09:15:09Z',
  server_modified: '2016-09-17T09:15:10Z',
  rev: '2aa3ae00edcb88',
  size: 5505
}

I also noticed that the uploaded zip has doubled in size compared to the original zip. The original zip is 3.259 bytes (4 KB), the uploaded zip is 5.505 bytes (8 KB).

If it helps, I am running node 4.5.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Does It Mean When Your File Is Corrupt?
A corrupted file is essentially a file that has become damaged and refuses to open properly.
Read more >
Excel document get corrupted when uploaded to Sharepoint
According to your description, you want to prevent the Excel files from getting corrupted when uploaded to SharePoint Online.
Read more >
Files are corrupted sometimes when uploaded with multipart ...
Sometimes (maybe one time in 20) multipart uploads of a 128MiB file get corrupted. I know they are corrupted because the SHA1 that...
Read more >
What Is A Corrupted File And How To Fix It? - Techslang
Files may get corrupted when they are saved or created. Some of the reasons include sudden office app glitches or compression app issues....
Read more >
All files got corrupted that i tried to upload on drive. How to ...
How to recover them?? I tried uploading 134 photos. None of them got uploaded and when i checked them again on my phone,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found