Hello Folks, I hope you guys are well.
Last week I am getting an issue in my Laravel Application which is regarding the S3 bucket.
Files, Images and PDF are not getting store in my S3 Bucket. The code which I have written is working fine for me for last 10 months in production environment.
Then I checked that code in my local machine which is (localhost) and that is working fine. Then I clear my Laravel Application its Cache , Views , Routes , Config. Also, checked my .env file which is same as local environment.
The last thing which I can do is check the incognito mode after clearing all the cache routes and other things. In incognito mode my files are getting uploaded for the production site but when I upload that image from the normal window its showing me the get file content error.
I am giving you the screenshots and the code which I am using let me know if you can help me with this and yes I know the problem is very strange.
My Controller Function
public function saveAboutBannerSlide(Request $request){
$banner_tile = $request->banner_title;
$banner_des = $request->banner_des;
//Getting File name form the form
$file = $request->file('banner_image');
//S3 OBJECT
$s3 = Storage::disk('s3');
$new = uniqid() . "_banner";
//Uploading With the New Name
$upload_path = 'uploads/manage-cms/aboutus-images/' . $new;
//Put File in S3 Bucket
$s3->put($upload_path, file_get_contents($file));
//Getting URL OF THE Image
$up_img = $s3->url($upload_path);
}
Error image while uploading image
Related
Currently I want to upload the images that the client chooses to the Amazon S3 service and in fact it seems that it already does so because it uploads a file and tells me that it weighs 92kb the same as the file I am choosing but when I want to open it with the path that is It gives me the following error:
The image <image path> cannot be displayed because it contains errors.
Code Laravel
public function SaveImage($request){
if ($request->hasFile('inputFile')) {
$image = $request->file('inputFile');
$fecha= date("m-d-y");
$name = $fecha."_".$request->txtNombre.'.'.$image->getClientOriginalExtension();
$destinationPath = public_path('UploadProfile');
$image->move($destinationPath, $name);
$filePath=$destinationPath."\\".$name;
$initPath="Perfil\\".$name;
Storage::disk('s3')->put($initPath, $filePath);
return $urlImage= Storage::cloud()->url($initPath);
}
}
the strangest thing is that it does not mark me errors, everything runs correctly but if it shows me that the files were uploaded in the panels of the buckets, besides if I upload directly through the buckets and open the path if it opens right way.
The image path would be as follows:
https://katanasystem.s3-us-west-1.amazonaws.com/Profile/01-05-20_david.jpg
Images not displaying in webpage interface while it was fine and displayed in localhost.
I made an app with Laravel 5.2 and it was correct in localhost but after updaing it online we faced a very bad problem. All images which come from database aren't showing in webpage interface. I am storing images in Laravel root directory storage folder and image links to database table. Each image gets the exact stored image URL value but is not displaying properly. Also when I copied the image URL and pasted it in my browser it said :
Whoops, looks like something went wrong
I am accessing images via this method
<img src="{{url::to('mvimage/'.$image->image) }}" />
I am accessing image via route.php by using this method
Route::get('mvimage/{file_name}', function($filename){
$path = storage_path('app').'\mvimage\\'.$filename;
$image = \File::get($path);
$mime = \File::mimeType($path);
return \Response::make($image, 200)->header('Content-Type', $mime);
});
I think the problem comes from the back slash..
Try with this
storage_path("app/mvimage/$filename");
Note :
In your view you should access the facade with URL not url
In your route file, you should be on the root namespace so no need for \ before File and Response
Well, I've uploaded an app to Heroku, and I've discovered that I can't upload files to it. Then I started to use Dropbox as storage option, and I've done a few tests, of send and retrieve link, and all worked fine.
Now, the problem is to use the uploadFile() method on DropboxAdapter. He accepts an resource as the file, and I did'nt work well. I've done a few tests, and still no way. Here is what I am doing, if anyone could me point a solution, or a direction to this problem, please. :)
Here is my actual code for the update user (Update the user image, and get the link to the file).
$input = $_FILES['picture'];
$inputName = $input['name'];
$image = imagecreatefromstring(file_get_contents($_FILES['picture']['tmp_name']));
Storage::disk('dropbox')->putStream('/avatars/' . $inputName, $image);
// $data = Storage::disk('dropbox')->getLink('/avatars/' . $inputName);
return dd($image);
In some tests, using fopen() into a file on the disk, and doing the same process, I've noticed this:
This is when I've used fopen() on a file stored on the public folder
http://i.imgur.com/07ZiZD5.png
And this, when i've die(var_dump()) the $image that I've tried to create. (Which is a suggestion from this two links: PHP temporary file upload not valid Image resource, Dropbox uploading within script.
http://i.imgur.com/pSv6l1k.png
Any Idea?
Try a simple fopen on the uploaded file:
$image = fopen($_FILES['picture']['tmp_name'], 'r');
https://www.php.net/manual/en/function.fopen.php
You don't need an image stream but just a filestream, which fopen provides.
I have an image uploading script which works fine when uploading an image to the domain it's on, but I also need to upload the same image to an alternate subdomain.
Here's the bit of the code I'm having trouble with.
$filename = "../../images/home-features/" . $imagename;
$filename2 = "/var/www/vhosts/domain.org/httpdocs/images_home/features/" . $imagename;
imagejpeg($tmp,$filename,60);
imagejpeg($tmp,$filename2,60);
It's the second of the two which is not uploading. I don't get any errors - it's as if it has worked but then the image is not there.
Any ideas?
i dont know exactly why the second image isnt coming through the same resource. maybe the resource needs rewinding/resetting.
But WHY let the server do the same work all over again? Just copy the first file as the second!
copy($filename, $filename2);
ps. did you check the directory for the second file is writable?
How can I upload image files to Dropbox with the Jimscode PHP Dropbox component for CodeIgniter? It uses the add() method for uploading files. It successfully uploads all other files types (e.g. pdf) to Dropbox. But when I upload image files, it uploads empty files to Dropbox. That is of 0 bytes and unable to preview that image in Dropbox. My code:
public function add($dbpath, $filepath, array $params = array(), $root=self::DEFAULT_ROOT)
{
$dbpath = str_replace(' ', '%20', $dbpath);
$filename = rawurlencode($filepath);
$parstr = empty($params) ? '' : '&'.http_build_query($params);
$uri = "/files_put/{$root}/{$dbpath}?file={$filename}{$parstr}";
//$uri = reduce_double_slashes("/files/{$root}/{$dbpath}?file={$filename}{$parstr}");
$specialhost = 'api-content.dropbox.com';
return $this->_post_request($uri, array('file'=>'#'.$filepath), $specialhost);
}
Is there an API method I can use directly with curl and PHP?
I'm not sure what version you are using but the reduce_double_slashes line isn't commented out normally. That wouldn't cause some file types to upload and not others though. Is the failure with a single image or does it fail to upload with every image.
You can also set the DEBUG const in the library to true and have it write debug information out to your error log. That might help you figure out where the issue is happening.