Backpack Media Library - laravel

I am using laravel backpack.
I want to open media gallery in backpack when click on browse button.
I have added file manager and the images are stored in amazon s3. The images in s3 gallery will open, when click on browse button.
Please help me, how can I open the media gallery?
I have used field type as browse. But, when I select image and trying to save it in amazon s3, it is not saving. Please help me to solve this issue.
My field:
$this->crud->addField([
'label' => "Image",
'name' => "image",
'type' => 'browse',
'upload' => true,
'disk' => 's3',
],
'both');
My model's mutator method:
public function setImageAttribute($value) {
$attribute_name = 'image';
$disk = 's3';
$destination_path = '';
$this->uploadFileToDisk($value, $attribute_name, $disk, $destination_path);
}

Related

Access my files from the public directory

With the upload_multiple field / column, I need to open file with the existing link.
However when I open the link I get a 404.
This is how I do things :
// setupCreateOperation
CRUD::addField([
'name' => 'documents',
'label' => 'Documents',
'type' => 'upload_multiple',
'upload' => true,
]);
// setupShowOperation
CRUD::addColumn([
'name' => 'documents',
'label' => 'Documents',
'type' => 'upload_multiple',
]);
// Model
public function setDocumentsAttribute($value)
{
$attribute_name = "documents";
$disk = "public";
$destination_path = "documents";
$this->uploadMultipleFilesToDisk($value, $attribute_name, $disk, $destination_path);
}
So the documents are in storage > app > public > documents.
What appears in the form (show or edit) : http://localhost/documents/65004a2cdbd104406b025d14c6519ce9.pdf (404)
And I already exectuted php artisan storage:link
If you have any idea, that would be nice...
Thank you!
If you can show your route:
http://localhost/documents/65004a2cdbd104406b025d14c6519ce9.pdf (404)
when you work in localhost with Laravel, you need proporcionate complete url.
Your url to access this resource sould be:
assets('storage/documents/'.65004a2cdbd104406b025d14c6519ce9.pdf)
with this example, try generate link, should can show your documents.
Your problem it´s you need access to storage path.
Sorry for my bad english. I hope help you

Laravel Backpack not uploading image

I am attempting to upload a file (country flag) to a simple table countries which should be saved in a "flags" folder of public.
In my add field declaration I have
$this->crud->addField([ // image
'label' => "flag",
'name' => "flag",
'type' => 'image',
'upload' => true,
'disk' => 'flags', // in case you need to show images from a different disk
'prefix' => 'flags/'
and in the filesystems file I have:
'flags' => [
'driver' => 'local',
'root' => public_path('flags'),
'url' => '/flags',
'visibility' => 'public',
],
When I upload it tells me that the field is too short (it is varchar 255) as it seems to want to store the file as data image.
You should take another look at all the instructions for the image field type, in the documentation. Backpack does not take care of the uploading for you - you need an accessor on your Model, so you can choose where it's uploaded and how. If you don't do that, Backpack will try to store it as Base64 in your database - which isn't a good idea in most cases.
Example accessor for flag:
public function setFlagAttribute($value)
{
$attribute_name = "flag";
$disk = "public_folder";
$destination_path = "uploads/folder_1/subfolder_3";
// if the image was erased
if ($value==null) {
// delete the image from disk
\Storage::disk($disk)->delete($this->{$attribute_name});
// set null in the database column
$this->attributes[$attribute_name] = null;
}
// if a base64 was sent, store it in the db
if (starts_with($value, 'data:image'))
{
// 0. Make the image
$image = \Image::make($value)->encode('jpg', 90);
// 1. Generate a filename.
$filename = md5($value.time()).'.jpg';
// 2. Store the image on disk.
\Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream());
// 3. Save the path to the database
$this->attributes[$attribute_name] = $destination_path.'/'.$filename;
}
}

backpack for laravel segment missing during upload

I created a CRUD (using backpack crud for laravel )for uploading certificates, when i upload the pdf I use
$this->crud->addField([
'name' => 'respaldo',
'label' => 'Respaldo',
'type' => 'upload',
'upload' => true,
'wrapperAttributes' => [
'class' => 'form-group col-md-6'
],
]);
when i want to see the link of the uploaded file, storage is missing from the route so i added it to a mutator ,see below
public function setRespaldoAttribute($value)
{
$attribute_name = "respaldo";
$disk = "public";
$destination_path = "uploads/respaldos";
$this->uploadFileToDisk($value, $attribute_name, $disk, $destination_path);
}
public function getRespaldoLink() {
return '<a href="'.asset('storage/'.$this->respaldo).'" target="_blank">
Descargar</a>';
}
Now when clicking on the link it's displayed on the listview, the problem is when i click on edit , "storage" segment is missing there so i get 404 instead. see image
I got the same issue and tried to amend the link before displaying it on browser for user to preview in Update or Show CRUD.
The issue is whatever the path is stored inside your database, it will pop up on browser without the head folder. As we know, we can amend the head folder with Laravel LIKE asset('storage/'.$file_path)
So, you need to update the path before storing into database.
Search and Update file HasUploadFields.php
Update this line with add-on 'storage/' Like this:
$this->attributes[$attribute_name] = 'storage/' . $file_path;
Do same for uploadMultipleFilesToDisk method
Now for all new file uploaded, it will add-on 'storage/' before stored file path

Cake PHP Upload plugin - How to store the thumbnail path in the database

I have installed Upload plugin for cakephp.
I've been trying to figure out how to store the thumbnail path or thumbnail name inside a field called image_thumb in my table called Portfolio. I want to store this the same way I can store the original image name. The dir option for the image is there but there is no such thing for thumbnail dir.
My model code where I used upload plugin is this:
public $actsAs = array(
'Upload.Upload' => array(
'image' => array(
'fields' => array(
'dir' => 'image'
),
'thumbnailSizes' => array(
'small' => '640x480',
),
'thumbnailName' => '{filename}_{size}_{geometry}',
'thumbnailPath' => '{ROOT}webroot{DS}img{DS}{model}{DS}Thumbnails{DS}'
)
)
);
Controller, the add function, where the plugin happens I assume (I haven't changed anything here though,
it is the baked code)
public function admin_add() {
$this->layout='admin';
if ($this->request->is('post')) {
$this->Portfolio->create();
if ($this->Portfolio->save($this->request->data)) {
$this->Session->setFlash(__('The portfolio has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The portfolio could not be saved. Please, try again.'));
}
}
}
When the image path is uploaded in database, the image itself and thumbnails are saved in the specified directories in my application. But I want to save the path of the thumbnails inside the database soe that I can use it in my view.
Would really appreciate the help as I'm so new to cakephp and I have to figure it out in a short amount of time.
Thanks.
You may make mistake in here it should be
'fields' => array(
'dir' => 'image_thumb' //table field name
),

MAGENTO : Add image field in custom module

I'm creating a module and i want to add a picture in the edit page (back office), i do this :
$fieldset->addField('photo', 'image', array(
'label' => "image",
'required' => false,
'name' => 'image',
));
the input is present in the page but in my controller i don't have any information about this picture, does someone can tell me how i can do this ?
Thanks.
Refer the image upload article
http://www.magentocommerce.com/wiki/5_-_modules_and_development/admin/how_to_create_pdf_upload_in_backend_for_own_module

Resources