Upload file to Amazon S3 failing only first time - laravel-4

I am trying to upload files to amazon s3 bucket and its failing only first time. After first time, files upload successfully. Tried many ways can’t fix it. Please help.
The error I am getting is as follows:
Exception 'ErrorException' with message 'S3::inputFile(): Unable to open input file: C:\inetpub\temp\PHPTemp\php6C81.tmp' in C:\inetpub\websites\bizitask.com\app\libraries\S3.php:355
I am using an ajax form to upload the file and code in controller to upload the file is as follows:
if ($s3->putObjectFile(Input::file('file')->getRealPath(), 'bizitask', 'files/businesses/'.$business_id.'/'.$file_name, S3::ACL_PUBLIC_READ)) { return Redirect::to('customers/businesses/' . $business_id)->with('success', 'success'); }
I am using laravel 4.2

Related

Excel Import using Laravel Hosted in AWS Lambda giving error 'touch(): Unable to create file because Read-only file system

I am trying to import an excel sheet in Laravel, hosted in AWS Lambda and I am getting error
touch(): Unable to create file /var/task/storage/framework/laravel-excel/laravel-excel-ToQHNqV18ybdHCmqQFJKidLr5dSsWSUe.xlsx because Read-only file system
My code to import is
Excel::toArray(new ClientCompanyImport, $request->file('sales_accounts_sheet'));
Then I tried to mention the disc name as third parameter as
Excel::toArray(new ClientCompanyImport, 'mysheet.xlsx', 's3');
and uploaded 'mysheet.xlsx' file in s3 bucket path as 'storage/frameworks/laravel-excel/mysheet.xlsx'
Still I am getting same error. As I understand correctly, after this change, system is getting the file from S3 location, but still trying to keep the file temporary in default location, that is readonly in Lambda.
Laravel Version: 8
Laravel-Excel: 3.1
After reading a lot of articles and forums, I found the solution.
Main reason of above error is due to the readonly mode of AWS Lambda. By default the excel is trying to upload in the root folder, that is readonly in the case of Lambda and it fails.
Only editable path supported by Lambda is /tmp
The solution is to specify the path in config/excel.php
return [
'temporary_files' => [
'local_path' => sys_get_temp_dir(),
],
.
.
That is correct, by default the root path where your Laravel application runs is "read-only", Lambda provides a temporary directory where it is possible to perform write operations.
In your case the solution is adequate, but keep in mind that you can have the same problem with other services such as session and cache using the "file" driver.
You can write this little block of code inside your AppServiceProvider.php to change the "storage_path" that points to the root folder where your application lives.
public function register()
{
// Valid only in the production evironment.
if ($this->app->environment('production')) {
$this->app->instance('path.storage', '/tmp/laravel/storage');
}
}

Download response for S3 asset?

I'm trying to generate a download response by:
return response()->download('full URL to my asset on S3 via cloudfront');
But I'm getting an error stating that the file does not exist.
I've checked the path, and it loads fine in a browser window.
How can I generate a download response for my asset on S3 via cloudfront?

image uploader in post free ad page is not working in osclass

I am new to Osclass. I have purchased shopclass theme. we are using jquery fine uploader plugin for image upload. when we are uploading image it shows error.
"[FineUploader 3.8.0] Error when attempting to parse xhr response text (Unexpected token < in JSON at position 61)"-this is the error shown in console.
The image is uploaded into temp folder but it does not shown in post and also shows uploading error in user end.Please help me to solve this problem.

blueimp jQuery-File-Upload not working for laravel 5

i am using , https://github.com/blueimp/jQuery-File-Upload plugin for image upload using ajax call in laravel 5. i also refered article http://peterjolson.com/using-laravel-and-jquery-file-upload/. but i am getting the following error error
GET http://localhost:8000/...../server/php/ 500 (Internal
Server Error)
when i use https://github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin i get the same error. Can anyone help with this or please suggest any working image uploader with ajax call for laravel 5
There is a main.js file, you need to adjust the url there according to the path you store it:
url: '../../uploadimage/server/php/'

Upload to Amazon S3 with Codeigniter

I am developing an API using Codeigniter and I want to let users upload images to my Amazon S3 account. I am using Phils Restserver and Donovan Schönknecht S3 library (for Ci).
It works perfectly to upload a local file to Amazon but how can I get the image file
sent via normal external form?
Using the built in Ci upload library it works fine but then I have to store the files
locally on my own server and I want them on S3. Can the two be combined?
I guess what I am asking is how can I "get" the image file that is sent to the controller
and resize it and then upload it to S3?
Do I perhaps need to temporary save it on the local server, upload it to S3 and then remove it from the local server?
This is my "upload" modal:
// Load the s3 library
$this->load->library('S3');
// Make the upload
if ($this->s3->putObjectFile($args['local'], "siticdev", $args['remote'], S3::ACL_PUBLIC_READ)) {
// Handle success
return TRUE;
} else {
// Handle failure
return FALSE;
}
Thankful for all input!
If I understand you correctly, you want a user to upload an image via a form, resize that image, then transfer that to Amazon S3.
You'll have to store the file locally (at least for a few seconds) to resize it with CI. After you resize it, then you can transfer it to Amazon S3. In your success callback from the transfer, you can delete the image from your server.
You should definitely check out the CI S3 library. The "spark" is available here - http://getsparks.org/packages/amazon-s3/versions/HEAD/show

Resources