exceljs error when reading csv file uploaded from windows - node.js

When uploading csv file created by windows; an error is generated when trying to parse the file using exceljs.
Here is the error message:
message: "Can't find end of central directory : is this a zip file ?
If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html"

It happens because of the uploading stage, you haven't uploaded the file successfully so that can not reading later. Please double check whether you uploading or having the file on cloud storage successfully or not

Related

Don't overwrite existing file nodejs express-fileupload

I tried out the express-fileupload sample project, to test uploading files. However, if I upload a file with a name that is already uploaded e.g. test.jpg (uploaded) test.jpg (to be uploaded) it just overwrites the old file. Is there an easy way to prevent this or do I have to code something that checks if that file already exists.
Sample Project: https://github.com/richardgirges/express-fileupload/tree/master/example

Download xlsx file (or any formats that cannot be read by notepad) from Google Storage and store it locally

I currently have a node.js server running where I can grab a csv file stored in storage bucket and store that to a local file.
However, when I try to do the same thing with a xlsx file, it seems to mess up the file and cannot be read when I download it to a local directory.
Here is my code for getting the file to a stream:
async function getFileFromBucket(fileName) {
var fileTemp = await storage.bucket(bucketName).file(fileName);
return await fileTemp.download()
}
and with the data returned from above code, I store it into local directory by doing the following:
fs.promises.writeFile('local_directory', DataFromAboveCode)
It seems to work fine with .csv file but does not work with .xlsx file where I can open the csv file but xlsx file gets corrupted and cannot be opened.
I tried downloading the xlsx file directly from the storage bucket on google cloud console but it seems to work fine, meaning that somethings gone wrong in the downloading / saving process
Could someone guide me to what I am doing wrong here?
Thank you

Uploading zip file to sharepoint using REST is not saving the file contents

Uploading zip file to sharepoint using REST is not saving the file contents. The operation is sucessful. But when the file is downloaded from site to local machine, its failing to open the zip and showing 0 bytes
Did you follow:
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/upload-a-file-by-using-the-rest-api-and-jquery
Creating the item (with the meta data) in the library and upload the file (binary) are two seperate actions you have to handle to complete the upload. I think you only add an item to the library and not uploading the binary data?

CodeIgniter - Directory Traversal - sanitize_filename()

If I use the CodeIgniter File Upload Class and rename the image being uploaded using:
$config['file_name']
do I still have to use
$this->security->sanitize_filename()
on the image being uploaded by user?
just set $config['encrypt_name']; will automatically rename users uploaded file or image for more information check user guide of File uploading library
File Upload Library

With AWS S3 MultiPart upload to a named directory using C# and the .Net SDK

The following fails with this error message:
"The specified upload does not exist. The upload ID may be invalid, or the upload may have been aborted or completed."
UploadPartRequest uploadRequest = new UploadPartRequest()
.WithBucketName(IniValues.Instance.TargetBucketName)
.WithKey("junk/20070125.log")
.WithUploadId(initResponse.UploadId)
.WithPartNumber(i)
.WithPartSize(partSize)
.WithFilePosition(filePosition)
.WithFilePath("C:\\InetTemp\\Logs\\20070125.log");
The problem is with the ".WithKey("junk/20070125.log")". If I strip out the "junk/" it works perfectly.
So the question is, how to upload a file to a specific AWS directory? All the documentation I found shows tha correct way to be to prepend the directory name and a forward slash. What am I missing?
It turns out I was adding the folder name to the string after calling InitiateMultipartUploadRequest. Once I changed the key value to be consistent across the upload calls it began to work.

Resources