How to update stripe's legal_entity.verification.document with PHP ?
Is it a file to upload to stripe.
The legal_entity[verification][document] attribute should be set to a file upload's ID.
This part of the documentation explains how to upload a file using Stripe's API, and this part explains how to attach the uploaded file to a managed account.
You need to first pass the file to your server in multipart/form-data format. Get the path and add the path in Stripe FileUpload function.
You can even test the file upload by keeping the file manually in server directory and pass the file path to the function.
Below is the sample.
$account = \Stripe\Account::retrieve('acct_xxxxxxxxxxx');
$uploadedFile = \Stripe\FileUpload::create(
array("purpose" => "identity_document",
"file" => fopen('file.png', 'r')
)
);
You will get a success upload response with file id and this id you need to pass in legal_entity.verification.document like :
$account->legal_entity->verification->document = $uploadedFile->id;
$account->save();
Related
I want to use Composer's PHP wrapper to upload an image to CloudConvert. This image will come from a html form which users will fill. In the array that CloudConvert's start() function uses to upload a file, the key/value pair for an image file is:
<?php
$process->start([
"input" => "download",
"file" => "http://url/to/my/file.ext",
"outputformat" => "png",
......
......
],
]);
?>
The value associated with the 'file' key seems as if it must be a public URL. Ideally I would like to use the html form variable as the value for the 'file' key in the array. I've tried using the $_FILES array with both ['tmp_name] and ['name'] but both throw errors. I've also placed an image in the root directory and then used $img_filepath = fopen('./Post_box_Lake_District.jpg', 'r'); but that throws the following error: Uncaught CloudConvert\Exceptions\ApiException: Upload is not allowed in this process state in C:\xampp\htdocs\test_site\vendor\cloudconvert\cloudconvert-php\src\Process.php:80. I presume I could use the URLs for images stored on a file on my server but for the moment I'm storing images in a database. CloudConvert have a facility where users can upload their API but, if possible, I don't want to do that. I want everything to come through my server. So how can I upload images via CloudConvert's API. Thanks for any help in advance.
Have tried the API call as listed on Podio dev site to upload a file and I am not getting much joy.
I am trying to "Upload a file" in the first instance using the POST operation and passing the json with the source url to the endpoint as specified.
I can use other methods just fine but since there is little in the way or error feedback I am stuck I keep getting error 404
I have used - https://developers.podio.com/doc/files/upload-file-1004361
(have tried both GET & POST)
image of method with error i get
Upload file method that you are trying to use (https://developers.podio.com/doc/files/upload-file-1004361) is expecting file path which is supposed to be local file but not url.
Here is example of how it should be used:
http://podio.github.io/podio-php/api-requests/
$file = PodioFile::upload($path_to_file, $filename_to_display);
print 'File uploaded. The file id is: '.$file->id;
Here is another example on how to work with files:
https://developers.podio.com/examples/files
I am developing a REST API using Laravel 5.1 that has use case as following: receive a base 64 decoded PDF, and return a workspace ID of a Document Management System (DMS) from the uploaded file. The DMS service that I use in this case is Alfresco.
Current Condition
The application succeed to receive base 64 string and decode it to a file. I store the decoded file into system temporary directory, and try to upload it to the Alfresco. I have previously built function that receive a file from a form request to be stored in the Alfresco, and it works. Here is the declaration and parameters stated in the function:
public static function uploadDocument(
$doc, // <-- Okay by form request, not okay by the API decoded file
$user, // credential
$password, // credential
$params = array() // array that contains ACE
)
{
However, when I tried to use the same function with different document source, it failed. By different document source, I mean the source comes from the decoded base 64, and can be seen as follow:
// Decrypt base64
$fileData = base64_decode($request->input('file'));
// Save the decoded file to a temp directory
$tmpDir = sys_get_temp_dir();
$fileName = $request->input("fileName");
$pdfFile = fopen("$tmpDir/$fileName", 'w');
fwrite ($pdfFile, $fileData);
// Upload the decrypted file to the Alfresco
$alfUsername = Config::get('alfresco.CMIS_BROWSER_USER');
$alfPassword = Config::get('alfresco.CMIS_BROWSER_PASSWORD');
$assignees = ['assignees' => []];
$alfObjId = Alfresco::uploadDocument(
$pdfFile,
$alfUsername,
$alfPassword,
$assignees
);
fclose ($pdfFile);
The Error
Call to a member function getClientOriginalName() on resource
That refers to this line:
$uniqueFileName = $alfresco
->getUniqueFileName([
'path' => $path,
'filename' => $doc->getClientOriginalName(), // <-- This line
'session' => $session
]);
Error screenshot
The Question
Can one uploads a decoded base 64 file to another service without using temporary file?
How can I convert the decoded file into a multipart form request or similar, in order that my upload function could consume?
Thank you.
Well, sure you can call other service without saving a temporary file. If the file is already in memory as a string you could use curl to send a new request sending the string as data. Using curl to create a request you could set the content type header to multipart form data
I am trying to download a file that I stored on S3 to my local Laravel installation to manipulate it. Would appreciate some help.
I have the config data set up correctly because I am able to upload it without any trouble. I am saving it in S3 with following pattern "user->id / media->id.mp3" --> note the fact that I am not just dumping files on S3, I am saving them in directories.
After successfully uploading the file to S3 I update the save path in my DB to show "user->id / media->id.mp3", not some long public url (is that wrong)?
When I later go back to try and download the file I am getting a FileNotFoundException at S3. I'm doing this.
$audio = Storage::disk('s3')->get($media->location);
The weird thing is that in the exception it shows the resource that it cannot fetch but when I place that same url in a browser it displays the file without any trouble at all. Why can't the file system get the file?
I have tried to do a "has" check before the "get" and the has check comes up false.
Do I need to save the full public URL in the database for this to work? I tried that and it didn't help. I feel like I am missing something very simple and it is making me crazy!!
Late answer but important for others,
$s3_file = Storage::disk('s3')->get(request()->file);
$s3 = Storage::disk('public');
$s3->put("./file_name.tif", $s3_file);
The response of $s3_file will be a stream, you can save that stream data to file using Laravel put file method, you will find this stream file in storage/public directory.
You can give your Content-Type as desired and Content-Disposition as 'attachment' because your files are coming from S3 and you have to download it as an attachment.
$event_data = $this->ticket->where('user_id', $user_id)->first();
$data = $event_data->pdf;
$get_ticket = 'tickets/'. $data;
$file_name = "YOUR_DESIRED_NAME.pdf";
$headers = [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="'. $file_name .'"',
];
return \Response::make(Storage::disk('s3')->get($get_ticket), 200, $headers);
Say, you have AWS S3 as your default storage.
And you want to download my_file.txt from S3 to my_laravel_project\storage\app\my_file.txt
And you want to make it a one-liner
Storage::disk('local')->put('my_file.txt', Storage::get('my_file.txt'));
I am using AWS PHP SDK. I uploaded a JSON file to S3 bucket. Now I would like to get the file contents(uploaded to S3 bucket), add some additional text to the grabbed file contents and update that file over the S3 bucket.
What I want is something like this:
file name: userlist.json
grab content of file using S3 provide methods
eg: existing file contents are {'abc','xyz'}
add additional contents {'abc','xyz'}, {'zxv','opiv','cvpo'}
update newly added content into S3 bucket file (userlist.json)
How we can do this ?
You can't add data to, or modify just part of an existing s3 object, you need to read the object, make changes to the object, and the write the entire object back to s3.
You can overwrite any file in s3.
When you write file in same location with same name then it remove old file and replace it with new one.
You can follow the following algorithm
step 1 : get the file content from a specific bucket using the function
return $result = $this->s3->getObject(array(
'Bucket' => bucket,
'Key' => 'file_name'
));
step 2: Write the return content in a local file.
step 3: Read the file and modify whatever you like. Save the file in local machine. Here you can save the file in different extension.
step 4: Upload the file in the desired bucket. Remember it s3 bucket shall not give immediate update if you overwrite the file with same name.
step 5:End