I am working with specific API and I need to pass a file(image/pdf) to API as following way.
$file = new CURLFILE('/Users/my-name/Downloads/500-536x354.jpeg')
But I have file(image) as a Web URl like https://example.com/image.png
How can I pass https://example.com/image.png as same as new CURLFILE('/Users/my-name/Downloads/500-536x354.jpeg')`?
I just tried to pass this as like $file = new CURLFILE('https://example.com/image.png'), but it doesn't work.
Related
Trying to do something pretty simple but just need a bit of specific knowledge to get it to work.
I'm trying to submit an image in a post request to a post route in Laravel 5.5.
While retrieving a file from a request is easy with something like $file = $request->file('filename');,
Which will work with a html5 form that uploads a file and submits it to that route, what I am trying to do is upload a file via an API Blueprint.
I've unsuccessfully tried looking for the exact post data structure Laravel expects in order for a file to be retrieved with $file = $request->file('filename');,
Which I'm guessing is a standard, yet I have been unable to find an example of it as an API Blueprint.
If anyone has any pointers or suggestions, it would be much appreciated. Thanks!
submit an image in a post request to a post route in Laravel 5.5 use this code:
$imageTempName = $userdata->file('image_media')->getPathname();
$imageName = $userdata->file('image_media')->getClientOriginalName();
I think you need to try this process for upload file into the database within the directory using Laravel 5.
<?php
public static function upload_file(Request $userdata){
$imageTempName = $userdata->file('image_media')->getPathname();
$imageName = $userdata->file('image_media')->getClientOriginalName();
$path = base_path() . '/public/uploads/images/';
$userdata->file('image_media')->move($path , $imageName);
$data=array('media'=>$imageName);
$insert=with(new UserModel)->uploadFile($data);
}
?>
I started working on uploading a file to akamai netstorage using PHP and referred few API's in GitHub. I couldn't upload a video file. Though i can create and write contents in them.
<?php
require 'Akamai.php';
$service = new Akamai_Netstorage_Service('******.akamaihd.net');
$service->authorize('key','keyname','version');
$service->upload('/dir-name/test/test.txt','sample text');
?>
I referred this API. I also referred few others but couldn't get the right way to upload a video/image file. The code which i wrote above is working perfectly. Now i need to upload a video file instead of writing contents to a text file.
There is a more modern library for Akamai's NetStorage, which is built as a plugin for FlySystem, the akamai-open/netstorage.
Once you have it installed, you need to setup the authentication and the HTTP client (based on Guzzle):
$signer = new \Akamai\NetStorage\Authentication();
$signer->setKey($key, $keyName);
$handler = new \Akamai\NetStorage\Handler\Authentication();
$handler->setSigner($signer);
$stack = \GuzzleHttp\HandlerStack::create();
$stack->push($handler, 'netstorage-handler');
$client = new \Akamai\Open\EdgeGrid\Client([
'base_uri' => $host,
'handler' => $stack
]);
$adapter = new \Akamai\NetStorage\FileStoreAdapter($client, $cpCode);
And then you can create the filesystem object, and upload the file:
$fs = new \League\Flysystem\Filesystem($adapter);
// Upload a file:
// cpCode, action, content signature, and request signature is added transparently
// Additionally, all required sub-directories are created transparently
$fs->write('/path/to/write/file/to', $fileContents);
However, because you're uploading a video file I would suggest you use a stream rather than reading the contents in to memory. To do this, you use writeStream() instead:
$fs = new \League\Flysystem\Filesystem($adapter);
$stream = fopen('/path/to/local/file', 'r+');
$fs->writeStream('/path/to/write/file/to', $stream);
I am trying to send a buffered video to save it as a file on my server.
Always the file is empty.
My js get the url "blob:https://..." and sends to the php that receive it.
$file = file_get_contents(url);
file_put_contents($video_url_mp4."helloWorld.webm",$file);
I tried send the video as canvas and i only get one frame.
suggest please
A blob url is only usable in the browser that created it. So you cant use it on your server or copy and paste it into another browser or send the link to your friend etc.
What you need to do is get the blob that url was created from and use a FormData object and upload that to your server.
I get a file with the content as string on my php but this is not in a video format.
my js:
var myFile = new File(video.src);
var fd = new FormData();
fd.append('data', myFile);
and my php:
$f = $_POST['data'];
$decode = base64_decode(preg_replace('/^data\:image\/webp\;base64\,/', '', $f));
what is wrong?
I'm using the Parse PHP SDK and trying to upload an image. The file successfully saves, however the URL for the file returned by the getUrl() ParseFile method returns a 403 forbidden when I try to view it. Viewing the file via the Parse data browser also returns a 403 error. I'm using Laravel, and have tried several different methods:
1) Upload the file to parse, save the object against the user and then access the File via the getURL() method:
$contents = Input::file('profile_picture');
$file = ParseFile::createFromData($contents, "profilePicture_".$contents->getClientOriginalName());
Auth::user()->set('profilePicture', $file);
// In My View
<img src="{{Auth::user()->get('profilePicture')->getUrl()}}"/>
The URL returned returns a 403 forbidden.
2) Upload the file to Parse and store the URL against the user
$contents = Input::file('profile_picture');
$file = ParseFile::createFromData($contents, "profilePicture_".$contents->getClientOriginalName());
Auth::user()->set('profilePicture', $file->getUrl());
// In My View
<img src="{{Auth::user()->get('profilePicture')}}"/>
I have also tried both the above using:
$file = ParseFile::createFromData($contents, "profilePicture".$contents->getClientOriginalExtension());
An example of the URL being returned looks like:
http://files.parsetfss.com/2ed712aa-99d8-4df1-8100-a1f907042d43/tfss-37d8f8e3-b8fc-4980-8d45-4a24957a5dc0-profilePicturepong.jpg
It was actually a case of me using the wrong method. I should have been using createFromFile
I am trying to get specific metadata of an image located in dropbox using PHP and the Dropbox API.
After I connect to dropbox and list the images, I do this:
$md = $dbxClient->getMetadata($path);
print_r ($md);
Where the $path is the directory to my image. This works perfectly but I need to get more metadata regarding GPS location. In the Dropbox API (general view for Python, PHP, Java etc.) it says I have to set "include_media_info" to true to get gps metadata.
Going to the PHP part it has the function GetMetaData() with only one parameter: string
($path The Dropbox path to a file or folder).
Is there a way to get detailed metadata using the Dropbox API for PHP?
As you noted, the PHP library doesn't support the include_media_info parameter, so you'd need to modify the source code of the library to add support.
E.g. you could add this method:
function getMetadataWithMediaInfo($path)
{
Path::checkArg("path", $path);
return $this->_getMetadata($path, array("include_media_info" => "true"));
}
I had a look at the source, try this:
$md = $dbxClient->_getMetadata($path,array("list" => "true"));
or edit the core getMetadata and change its hard coded parameter list to true