pionl / laravel-chunk-upload

The basic implementation for chunk upload with multiple providers support like jQuery-file-upload, pupload, DropZone and resumable.js
MIT License
617 stars 167 forks source link

Uploaded text files encoding is being changed #71

Closed Soremwar closed 5 years ago

Soremwar commented 5 years ago

Hi there,

I developed a dynamic uploader that takes some parameters for the file, uploads it into the server and then save it into a route defined by the parameters previously mentioned.

So far, the app has run smoothly uploading files up to 2GB and I was quite satisfied by the results. However that changed when the users notified me that some file they were uploading was getting "corrupted" when being loaded into the system.

It appears that the accents in the file are not being recognized by PHP and instead being replaced by "?" and by the time the file is rebuilt into the server, the data has been altered.

I've checked the documentation and so far nothing provides an explanation for this behavior so I'm fearing this is a PHP related problem rather than the Uploader, so I request your help to understand why this is happening.

This is my code:


//Uploads the file to the server
//Returns a response from the saveFile method
public function upload(Request $request){

   $receiver = new FileReceiver("file", $request, HandlerFactory::classFromRequest($request));
   $id = $request->id;
   $code = TBL_EJEC_PARAMETROS_CARGA::find($id)->COD_ARCHIVO;

   if ($receiver->isUploaded()) {
      $save = $receiver->receive();
      if ($save->isFinished()) {
         return $this->saveFile($save->getFile(), $code);
      }else{
         $handler = $save->handler();
         return response()->json([
            "done" => $handler->getPercentageDone(),
         ]);
      }
   } else {
      throw new UploadMissingFileException();
   }
}

//Moves the file to the destination path
//Returns the file code used to upload it
protected function saveFile(UploadedFile $file, $code){

   $fileName = $code.'.csv';
   $finalPath = storage_path($this->filePath);
   $file->move($finalPath, $fileName);

   return response()->json([
      'code' => $code
   ]);
}
nerg4l commented 5 years ago

Have you tried opening the "corrupted" file with a different encryption? This library handles files as byte streams so it does not modifies them.

Soremwar commented 5 years ago

Have you tried opening the "corrupted" file with a different encryption? This library handles files as byte streams so it does not modifies them.

You are totally right. Wasn't taking into account the different codifications a file can have when reading it.

Closing #71