jeudi 18 juin 2020

Unable to upload application/octet-stream image

I am trying to upload an image from my mobile (Xiaomi Note 7s) which mime-type is application/octet-stream. My application was developed in Laravel 5.1. While uploading the file when i print_r() the request or the $_FILES at the beginning of method, it is showing error in the log. Here is the log:

Array
(
    [image] => Array
        (
            [name] => IMG_20200602_140509.jpg
            [type] => 
            [tmp_name] => 
            [error] => 1
            [size] => 0
        )

)
Array
(
    [_token] => kmoocliMDPFWBhfgr0yEQXm830raxPcxYGPxc19i
    [image] => Symfony\Component\HttpFoundation\File\UploadedFile Object
        (
            [test:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 
            [originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => IMG_20200602_140509.jpg
            [mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => application/octet-stream
            [size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
            [error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 1
            [pathName:SplFileInfo:private] => 
            [fileName:SplFileInfo:private] => 
        )

)

When uploading i'm also trying to resize the image using Intervention/Image, which is showing below error which might be the case of file type.

NotReadableException in AbstractDecoder.php line 346:
Image source not readable

Here is my code which i am using to resize the image:

// getting the imagename using this method
$imageName = getFileName($request->file('image'));

$image_resize = Image::make(
    $request->file('image')->getRealPath()
);
$image_resize->resize(200, 200);
$image_resize->save('img/ProfilePicture/' . $imageName);

I've also tried to change the image drive from GD to Imagick. which did not help to solve this problem. I also tried to resize the image using Imagick methods directly, but same result. Here is my code which i'm using to resize image:

$imagick = new \Imagick($_FILES['image']['tmp_name']);
$imagick->resizeImage(200, 200, Imagick::FILTER_LANCZOS, 1);
$imagick->writeImage($imageName);
$imagick->destroy();

Can anyone help me out how i can resolve this issue!



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3hGUm2M
via IFTTT

Aucun commentaire:

Enregistrer un commentaire