Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to upload a file as part of body using the post request. #270

Closed
aayyaga opened this issue Mar 14, 2017 · 1 comment
Closed

How to upload a file as part of body using the post request. #270

aayyaga opened this issue Mar 14, 2017 · 1 comment

Comments

@aayyaga
Copy link

aayyaga commented Mar 14, 2017

Hi,
I'm new to the php and using this library too. I'm working on creating a api library to make rest api calls and process the data. I'm able to post simple form-data and process the response. But I am having issues with uploading a file as part of the body.

function createOrder($accesstoken, $file){
	$url = '/api/order/';
	$body = array('access_token' => $accesstoken, 'entry' => $file);
		
	$headers = array('Accept' => 'text/xml');
	
	$response = Requests::post($url, $headers, $body);
	
        var_dump($response->body);
	var_dump($response->body["orderId"]);
}

I want to pass a json file which contains the order information for processing. The error I get is string(133) "The only acceptable directives are '../email' and '../SupportRequest'. I understand that its not supported type right now?

I'm not sure how to pass a file with some json data to make a request and how to decode the json response object. Any help/suggestions are highly appreciated?

Thank you!

@rmccue
Copy link
Collaborator

rmccue commented Jun 9, 2017

You need to read in the file yourself:

$content = file_get_contents( $file );

Support for file pointers is being tracked in #34.

@rmccue rmccue closed this as completed Jun 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants