我尝试将文件发送到api adobe sign,但始终返回此错误消息。
我已经在Postman上进行过尝试,当我发布帖子时一切都很好,但是当我收到答案时,这是当我省略content-type时,但是在应用程序内部我收到一个错误:我需要content-type 。
我已经尝试过使用“ multiform / form-data”,它给了我同样的错误
public static function sendTransientDocument($method, $codeAuthorization, $fileName, $file, $path)
{
$file_path = public_path('files/'.$file);
$file_stream = Psr7\FnStream::decorate(Psr7\stream_for(file_get_contents($file_path)), [
'getMetadata' => function() use ($file_path) {
return $file_path;
}
]);
$client = new Client();
$multipart_stream = new Psr7\MultipartStream([
[
'name' => 'File',
'contents' => $file_stream
]
]);
$boundary = '----WebKitFormBoundary7MA4YWxkTrZu0gW';
$multipart = [
[
'name' => 'file',
'contents' => fopen('files/'.$file , 'rb'),
'headers' => [ 'content-type' => 'multipart/form-data', 'name' => 'file'],
]
];
$params = [
'headers' => [
'Content-Type' => 'multipart/form-data; boundary='.$boundary,
'cache-control' => 'no-cache',
'accept' => 'application/json',
'Authorization' => self::$BEARER . $codeAuthorization,
'x-on-behalf-of-user' => '',
'content-disposition' => 'form-data',
],
'body' => new MultipartStream($multipart_stream, $boundary)
];
//$fields = ['file' => ''];
// $fields['file'] = fopen(public_path('files/' . $file), 'rb');
$request = $client->request($method, self::$TRANSIENT_DOCUMENT_REQUEST . self::$TRANSIENT_DOCUMENT_ENDPOINT, $params );
/* 'headers' => [
'content-type' => 'multipart/form-data',
'cache-control' => 'no-cache',
'accept' => 'application/json',
'Authorization' => self::$BEARER . $codeAuthorization,
'x-on-behalf-of-user' => ''],
'multipart' => [[
'name' => $file,
'contents' => fopen('files/' . $file, 'r', true),
'headers' => ['Content-Type' => 'application/pdf','Content-Disposition' => 'form-data', 'File-Name' => $file]
]
]]);*/
try {
$response = $request->getBody()->getContents();
//$response = $request->send($request);
return $response;
} catch (HttpException $ex) {
return $ex;
}
}
}