मैं पोस्टमैन का उपयोग करके एक एपीआई एंडपॉइंट पर एक फ़ाइल अपलोड करने में सक्षम हूं।Guzzle 6 का उपयोग करके फ़ाइल अपलोड करें एपीआई एंडपॉइंट
मैं अनुवाद करने के लिए है कि एक रूप से एक फ़ाइल अपलोड, यह Laravel का उपयोग करने और अंत बिंदु guzzle 6 का उपयोग करने के लिए पोस्ट
यह कैसे डाकिया में लग रहा है का स्क्रीनशॉट (मैं जानबूझकर बाहर छोड़ दिया पोस्ट URL अपलोड करने में कोशिश कर रहा हूँ
POST /api/file-submissions HTTP/1.1
Host: strippedhostname.com
Authorization: Basic 340r9iu34ontoeioir
Cache-Control: no-cache
Postman-Token: 6e0c3123-c07c-ce54-8ba1-0a1a402b53f1
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="FileContents"; filename=""
Content-Type:
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="FileInfo"
{ "name": "_aaaa.txt", "clientNumber": "102425", "type": "Writeoff" }
----WebKitFormBoundary7MA4YWxkTrZu0gW
नीचे है फ़ाइल और अन्य जानकारी को बचाने के लिए नियंत्रक समारोह:)
नीचे पाठ यह है जब आप डाकिया में "कोड बनाएं" लिंक पर क्लिक करें उत्पन्न करता है । फ़ाइल सही तरीके से अपलोड होती है, मैं फ़ाइल जानकारी प्राप्त करने में सक्षम हूं।
मुझे लगता है कि मेरे पास जो समस्या है, वह सही डेटा के साथ मल्टीपार्ट और हेडर सरणी सेट कर रहा है।
public function fileUploadPost(Request $request)
{
$data_posted = $request->input();
$endpoint = "/file-submissions";
$response = array();
$file = $request->file('filename');
$name = time() . '_' . $file->getClientOriginalName();
$path = base_path() .'/public_html/documents/';
$resource = fopen($file,"r") or die("File upload Problems");
$file->move($path, $name);
// { "name": "test_upload.txt", "clientNumber": "102425", "type": "Writeoff" }
$fileinfo = array(
'name' => $name,
'clientNumber' => "102425",
'type' => 'Writeoff',
);
$client = new \GuzzleHttp\Client();
$res = $client->request('POST', $this->base_api . $endpoint, [
'auth' => [env('API_USERNAME'), env('API_PASSWORD')],
'multipart' => [
[
'name' => $name,
'FileContents' => fopen($path . $name, 'r'),
'contents' => fopen($path . $name, 'r'),
'FileInfo' => json_encode($fileinfo),
'headers' => [
'Content-Type' => 'text/plain',
'Content-Disposition' => 'form-data; name="FileContents"; filename="'. $name .'"',
],
// 'contents' => $resource,
]
],
]);
if($res->getStatusCode() != 200) exit("Something happened, could not retrieve data");
$response = json_decode($res->getBody());
var_dump($response);
exit();
}
त्रुटि मैं प्राप्त कर रहा है, यह कैसे Laravel के डिबगिंग दृश्य का उपयोग कर प्रदर्शित करता है के स्क्रीनशॉट:
कृपया कोड केवल उत्तर पोस्ट नहीं है। अपने कोड के साथ कुछ पाठ जोड़ें। – rollstuhlfahrer