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.

File that was uploded on server-side using write method is corrupt. How can I fix issue?

See original GitHub issue
  1. ostrio:files@1.9.11
  2. METEOR@1.7.0.3
  3. Fedora 26
  4. Server

I am inserting a file into db.images, db.fs.files and db.fs.chunks using meteor-files or Ostrio-files (from VeliovGroup or keenethics). I am storing the files on GridFS. I installed gridfs-stream. I already have a meteor client app code that reads files from meteor-files and display them via a browser - this is how I view my newly inserted files, server-side. My server-side code for inserting files is as follows:

Images.write(this.bodyParams.file, {
  fileName: 'SignUpTermsAndConditions_' + this.bodyParams.name,
  type: 'application/vnd.oasis.opendocument.text',
  meta: {owner: this.userId,createdAt: new Date()}
}, function (error, fileRef) {
  if (error) {
	throw error;
  } else {
	console.log(fileRef.name + ' is successfully saved to FS. _id: ' + fileRef._id);
  }
},proceedAfterUpload=true);

I am able to insert a file client-side properly and when I view that file, the file is not corrupt. My client-side code for inserting into db.images, db.fs.files and db.fs.chunks is as follows:

Images.insert({
	file: file,  // where var file = e.currentTarget.files[0];
	fileName: fileName + e.currentTarget.files[0].name,
	onStart: function () {
	},
	onUploaded: function (error, fileObj) {
	  if (error) {
		alert('Error during upload: ' + error);
	  } else {
	  }
	},
	streams: 'dynamic',
	chunkSize: 'dynamic'
});

If you want me to provide the code that reads the file from GridFS client-side let me know.

As stated above my issue is that my server-side code for inserting a file, results in a corrupt file. Please help.

For your info: I am passing the file in a REST api post; I am passing the file in the body of the post.

For your info this is the error I get when trying to open the file in LibreOffice:

The file 'nSQGqasoSy6JF3DkJ-2.odt' is corrupt and therefore cannot be opened. LibreOffice can try to repair the file.

The corruption could be the result of document manipulation or of structural document damage due to data transmission.

We recommend that you do not trust the content of the repaired document.
Execution of macros is disabled for this document.

Should LibreOffice repair the file?

For your info I am reading the file in node.js using fs.readFile method. I have also tried reading the file locally within meteor.js instead but still results in a corrupt file. Here is my node.js code for fs.readFile and post

	fs.readFile('./Statement.odt', function read(err, data) { //where fs = require('fs')
		if (err) {
			throw err;
		}
		var file = data;
		
		request.post({
		  uri: url, 
		  headers:	 {
			'X-User-Id': userId,
			'X-Auth-Token': authToken
		  },
		  form: {
			  file: file,
			  name:"Statement.odt"
		  }
		}, function(err, httpResponse, body) {
		  if (err) {
			return console.error('post failed:', err);
		  }
		
		  console.log('Get successful!  Server responded with:', body);
		});
	});

For your info: I have tried reading a pdf document instead of a LibreOffice document but also results in a corrupt file. Please help!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
yushaUzumocommented, Jul 26, 2018

You are correct. Silly of me.

0reactions
yushaUzumocommented, Jul 26, 2018

And thanks for nudging me in the right direction.

Read more comments on GitHub >

github_iconTop Results From Across the Web

File uploaded through request is corrupt on the other end #1160
However, when I use the Node code to send the file to my own "conversion" server on localhost, I can't read the file,...
Read more >
C# - File is corrupt after uploaded to server - Stack Overflow
I think the problem is on encoding process Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()); , but I don't know how to resolve it. public ...
Read more >
What Does It Mean When Your File Is Corrupt?
A corrupted file may not open at all, or may show an error if it does. These damaged files are self-contained, meaning they...
Read more >
Data corruption when multiple users perform read and write ...
Fixes an issue in which data corruption occurs when multiple users perform read and write operations to a shared file when SMB2 is...
Read more >
Unrestricted File Upload - OWASP Foundation
Uploaded files might trigger vulnerabilities in broken libraries/applications on the server side (e.g. ImageMagick flaw that called ImageTragick!). Uploaded ...
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