0
我生成了這個Postman代碼片段,並希望在Talend中使用它,但我不知道如何設置文件名,以便它從本地驅動器。下面是代碼:OkHttpClient - 如何設置「[object Object]」到本地文件
OkHttpClient client = new OkHttpClient();
File sourceFile = new File("/Users/secret/Desktop/temp/16-27513/Digital Storefront Receipt.png");
MediaType mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001");
RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"uploadedFile\"; filename=\"[object Object]\"\r\nContent-Type: false\r\n\r\n\r\n-----011000010111000001101001--");
Request request = new Request.Builder()
.url("https://secret.attask-ondemand.com/attask/api-internal/upload/?apiKey=secret")
.post(body)
.addHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001")
.addHeader("cache-control", "no-cache")
.build();
Response response = client.newCall(request).execute();
String json = response.body().string();
System.out.println(json.toString());
這是本地文件我想的翻譯:引用:「/用戶/祕密/桌面/溫度/ 16-27513 /數字店面Receipt.png」
一直咀嚼幾個小時,沒有運氣。任何幫助深表感謝。
這是否編譯?如果是這樣,當你運行它會發生什麼? –
它的確如此。由於該文件沒有添加到RequestBody中,該文章僅創建一個沒有文件的shell。 –
這是後的結果:{ 「數據」:{ 「把柄」:「811bc97b1d16493e9e7caea123f06b7b」 } } –