Image not displayed in postman (readable) using Laravel API - laravel

The image is saved to the database and file path specified in the response. Trying to display the image or download it, it is not the displayed. I tried to read the same image but it is working.
storage_path('app/uploads/images/3.png')
I read the 3.png stored in the directory and it is working without displaying error but to display the image it doesn't display image.
[![if (empty($imag)){
return response()->json(\[
'success' => false,
'message' => 'There was a problem creating the postcard!'
\], 201);
}
return response()->json(\[
'success' => true,
'data' => file_get_contents(storage_path('app/public/uploads/images/'.$exportName)),
'message' => 'Postcard created successfully!'
\],200);
}
The directory where the image is saved is storage/app/public/uploads/
I used php artisan storage:link

Your storage path is
App/upload/images/3.png
And you are uploding image in
App/upload/public/images/3.png
So database is storing above path and image is not uploded in above path
Just remove public from above path it works...

Related

How to stop tinyMCE 5 to add ../../../../ before an absolute url received from alexusmai filemanager?

I am using Laravel 8, tinyMCE 5 and Alexusmai filemanager. My images are in the /public/assets/images folder.
The 'assets' disk is setup in config/filesystems.php :
// assets folder in public path
'assets' => [
'driver' => 'local',
'root' => public_path('assets'),
'url' => '/public/assets',
'visibility' => 'public',
]
FM returns the correct relatrive url, i.e. public/assets/images/xxx.jpg in a form field as a stand alone.
In tinyMCE 5, the same url is returned to the editor (the image is visible) but as soon as I look in the source3 code, the img scr is replaced by "../../../../public/assets/images/xxx.jpg". Why? How can I stop tiny to do that?
update...
It also seems that sometimestiny only adds ../ before public/assets... which results in the image not showing in the editor but displaying correctly in the website page. Weird!
How can I stop that please...
Seems like this is TinyMCE's "url handling": https://www.tiny.cloud/docs/configure/url-handling/
Try to add convert_urls: false to tinymce.init

How to send blade as attachment in pdf format in laravel?

I want to send blade file as attachment in mail with laravel. I am
writing below code for this but its not working.
Below is my controller where i am getting data from form and then send
this data to another controller where my attachment function is
called.
$data = array('shareholders'=>$request->com_shareholder_count,'contract_send'=>$request->contract_send);
$to = $mail_log->to_email_id = $request->email_id;
$mail = Mail::to($to)->send(new SendMailable($data));
This is my SendMailable controller :
$director_info_pdf = view('directors_info',compact('data'))->render();
On return this variable it shows me error :
message: "Invalid view.", exception: "InvalidArgumentException",…}
exception: "InvalidArgumentException"
file: "C:\xampp\htdocs\caps_admin\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php"
line: 285
message: "Invalid view."
After this line i am writing code to attach my files. where i am sending some files other 3 files are directly send from folder. And last one is attached from blade file.
->attachdata($director_info_pdf, 'dynamic_data.pdf')
->attach( $public_path.'/'.'contract.pdf', [
'as' => 'contract.pdf',
'mime' => 'application/pdf',
])
->attach($public_path.'/'.'HMRC.pdf',[
'as' => 'HMRC.pdf',
'mime' => 'application/pdf',
])
->attach($public_path.'/'.'clientR3.pdf',[
'as' => 'contract1.pdf',
'mime' => 'application/pdf',
]);
I am able to send mail with all 4 files as attachment. But when i am trying to open my files in mail rest 3 files are working as pdf. but ->attachdata($director_info_pdf, 'dynamic_data.pdf') this file get corrupted.
I dont know how to first change this file into pdf and then send as attachment.
I am using snappy for pdf.
I think you want to send pdf as an attachment in your email without saving it in your system .
your can refer the following code to do this .
public function sendmail()
{
$data["email"]='useremail#gmail.com';
$data["client_name"]='user_name';
$data["subject"]='sending pdf as attachment';
//Generating PDF with all the post details
$pdf = PDF::loadView('userdata'); // this view file will be converted to PDF
//Sending Mail to the corresponding user
Mail::send([], $data, function($message)use($data,$pdf) {
$message->to($data["email"], $data["client_name"])
->subject($data["subject"])
->attachData($pdf->output(), 'Your_Post_Detail.pdf', [
'mime' => 'application/pdf',
])
->setBody('Hi, welcome user! this is the body of the mail');
});
}
hope it helped you .
for better understanding you can follow this article
how to send pdf as an attachment in email in laravel
I dont know how to first change this file into pdf and then send as attachment. I am using snappy for pdf.
So that's the problem right there. You are attaching an HTML file, and simply naming it as if it's a PDF. That won't work. You do indeed need to generate this PDF from the HTML view that you render.
Here is the documentation for snappy:
https://github.com/barryvdh/laravel-snappy#usage
I suggest you to read up on it, as the examples given there are pretty straight forward and easy to understand.
This is untested, but if you've set up Snappy correctly, based on your code, something like this should work:
$snappy = App::make('snappy.pdf');
$director_info_pdf = $snappy->getOutputFromHtml(view('directors_info',compact('data'))->render());

Laravel 4 imagecache intervention not displaying images

Here's the product page with an imagecached image: http://kmk-prof.kz/product/dx700lc
As you can see - image is not being displayed and has following url: /imagecache/catalogue/dx700lc-541a82fe99ac3.jpg
But when i try to browse that image just in my uploads folder - http://kmk-prof.kz/uploads/dx700lc-541a82fe99ac3.jpg it displays just fine.
Why could imagecache not work?
Here's the imagecache config.php:
'route' => 'imagecache',
'paths' => array(
public_path('uploads'),
),
'templates' => array(
'catalogue' => function($image) {
return $image->fit(213, 213);
},
),
It's very hard to tell you why the image is not displaying without any code.
Looking at the site, your image (in the html) is looking for a file in /imagecache/catalogue/dx700lc-541a82fe99ac3.jpg when your file is in uploads/dx700lc-541a82fe99ac3.jpg.
you can do 2 things:
change the code to load the file from uploads/dx700lc-541a82fe99ac3.jpg.
or, change your image path to /imagecache/catalogue/dx700lc-541a82fe99ac3.jpg
if you want more help, please post your code.
PS. your IMAGE URL link doesn't work ^_^

error with upload images in Attachments using Croogo and cakephp

Hope someone can help me!
I'm trying to upload an image in Attachments and insert image in a page using croogo.
And when I upload i keep getting the same error message:
Security Error
The requested address was not found on this server.
Request blackholed due to "auth" violation.
The images are saved in the uploads folder but i cant get them to display on the page.
Just add some line of code in your controller
public function afterFilter() {
if (($this->request->isPost() || $this->request->isPut()) && empty($_POST) && empty($_FILES)) {
$this->Security->csrfCheck = false;
}
}
OR
May be you forgot to define multipart in your form.
echo $this->Form->create('Something', array( 'type' => 'file'));
Hope this help you.

yii unsecure attribute while using mimetypes file validation

i use the following mime type file validation
array('image', 'file', 'allowEmpty' => true,'mimeTypes'=>'image/gif, image/jpeg, image/jpg, image/png', 'on' => 'update')
works well if a file doesnt have the right mime type.
but if the validation is successful, the logg sais
2012/09/27 17:13:02 [warning] [application] unsafe Attribut "image" couldnt be set.
but it is defintily declared as save
array('image', 'safe', 'on' => 'update')
thats why i receive an error like this
finfo_file(C:\xampp\tmp\php3729.tmp): failed to open stream: No such file or directory
$mimeType=finfo_file($info,$file->getTempName());
seems, that the file cant be saved i its unsafe attribute.
the strange thing is, if i uncomment the validation rule with mimeTypes check, everthing works fine.
in my controller i set the image file like this
if (isset($_POST['User'])) {
$user->attributes = $_POST['User'];
$user->image = CUploadedFile::getInstance($user, 'image');
if ($user->validate()) {
I believe you run $user->image->saveAs($path) before saving the whole model, that's why it's trying to validate your file in temporary folder when it is already moved to the $path.
So, use $user->validate() or run saveAs($path) after saving model.

Resources