Commit 0a44e592 by Yu-Tung

TEST

parent 1bf78a2e
...@@ -33,8 +33,8 @@ dependencies { ...@@ -33,8 +33,8 @@ dependencies {
implementation 'io.reactivex.rxjava2:rxjava:2.0.7' implementation 'io.reactivex.rxjava2:rxjava:2.0.7'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1' implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'com.squareup.okhttp3:okhttp:4.7.1' implementation 'com.squareup.okhttp3:okhttp:3.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.7.1' implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0'
// retrofit // retrofit
implementation 'com.squareup.retrofit2:retrofit:2.2.0' implementation 'com.squareup.retrofit2:retrofit:2.2.0'
......
...@@ -32,6 +32,7 @@ import com.example.audiovisualrecord.utils.api.searcheqkd.EQKDResponse; ...@@ -32,6 +32,7 @@ import com.example.audiovisualrecord.utils.api.searcheqkd.EQKDResponse;
import com.example.audiovisualrecord.utils.api.searchmntfct.MNTFCTResponse; import com.example.audiovisualrecord.utils.api.searchmntfct.MNTFCTResponse;
import com.example.audiovisualrecord.utils.api.searchpmfct.PMFCTResponse; import com.example.audiovisualrecord.utils.api.searchpmfct.PMFCTResponse;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
...@@ -42,6 +43,10 @@ import java.util.List; ...@@ -42,6 +43,10 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType; import okhttp3.MediaType;
import okhttp3.MultipartBody; import okhttp3.MultipartBody;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
...@@ -399,7 +404,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie ...@@ -399,7 +404,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
String apiname = "SYNO.FileStation.Upload"; String apiname = "SYNO.FileStation.Upload";
String method = "upload"; String method = "upload";
String version = "2"; String version = "2";
String sid = "lRlPHRE7r9hm---3DSmlBx_r4gTaMuYkASLtpKHKp0c3M1jgiWwzGtQqj5d6OXoggCk1dIvHz7tUvhCgWnIJkY"; String sid = "Tx2aTlIDdA5zLsxYDOYP95AnZqw1iUaEBGnDbsszo1QqaJzIe3B7AFZY5quVBataqzdMt3h-59L-AUhM9R_5hQ";
String path1 = "/仁武氯乙烯廠製造一課/1_SOP導讀"; String path1 = "/仁武氯乙烯廠製造一課/1_SOP導讀";
Boolean a = true; Boolean a = true;
Boolean b = false; Boolean b = false;
...@@ -409,35 +414,46 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie ...@@ -409,35 +414,46 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
.readTimeout(30, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS) .writeTimeout(30, TimeUnit.SECONDS)
.build(); .build();
MediaType mediaType = MediaType.parse("application/octet-stream"); // MediaType mediaType = MediaType.parse("application/octet-stream");
MediaType mediaType = MediaType.parse("text/plain");
MultipartBody.Builder buildernew = new MultipartBody.Builder() MultipartBody.Builder buildernew = new MultipartBody.Builder()
.setType(MultipartBody.FORM) .setType(MultipartBody.FORM)
.addFormDataPart("path",""+path1) .addFormDataPart("api", apiname)
.addFormDataPart("method", method)
.addFormDataPart("version", version)
.addFormDataPart("_sid", sid)
.addFormDataPart("path",path1)
.addFormDataPart("create_parents", ""+b) .addFormDataPart("create_parents", ""+b)
.addFormDataPart("overwrite", ""+a) .addFormDataPart("overwrite", ""+a);
.addFormDataPart("file", "b525a7db0c5da640_1.jpg", // .addFormDataPart("file", "b525a7db0c5da640_1.jpg",
RequestBody.create(mediaType,new File("/storage/emulated/0/Watashi AHD V.2/temp_images/b525a7db0c5da640_1.jpg") // RequestBody.create(mediaType,new File("/storage/emulated/0/Watashi AHD V.2/temp_images/b525a7db0c5da640_1.jpg")
)); // ));
Log.e("test",""+buildernew.build().parts().get(0));
// .addFormDataPart("file","seg_1VID_20200604_155612.mp4.mp4", for (String path : uriList) {
// RequestBody.create(MediaType.parse("application/octet-stream"), File uploadFile = new File(path);
// "/storage/emulated/0/seg_1VID_20200604_155612.mp4.mp4")); // RequestBody fileBody = RequestBody.create(mediaType,uploadFile);
buildernew.addFormDataPart("file", uploadFile.getName(),
// for (String path : uriList) { RequestBody.create(MediaType.parse("application/octet-stream"), path));
// File uploadFile = new File(path); Log.e("pathname", uploadFile.getName());
// buildernew.addFormDataPart("file", uploadFile.getName(), Log.e("path", path);
// RequestBody.create(mediaType,uploadFile)); Log.e("file", uploadFile.getAbsolutePath());
// Log.e("path", uploadFile.getName()); }
// }
RequestBody body = buildernew.build(); RequestBody body = buildernew.build();
// buildernew.build();
Request request = new Request.Builder() Request request = new Request.Builder()
.url("https://fpcrtpms.synology.me:5001/webapi/entry.cgi?api="+apiname+"&method="+method+"&version="+version+"&_sid="+sid) .url("https://fpcrtpms.synology.me:5001/webapi/entry.cgi?api="+apiname+"&method="+method+"&version="+version+"&_sid="+sid)
// .url("https://fpcrtpms.synology.me:5001/webapi/entry.cgi") // .url("https://fpcrtpms.synology.me:5001/webapi/entry.cgi")
.method("POST", body) .method("POST", body)
// .header("api",apiname)
// .header("method",method)
// .header("version",version)
// .header("_sid",sid)
// .addHeader("Content-Type", "text/xml; charset=utf-8")
// .post(buildernew.build())
.build(); .build();
Log.e("requrstBody", request.toString());
try { try {
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
Log.e("response", response.body().string()); Log.e("response", response.body().string());
...@@ -459,24 +475,39 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie ...@@ -459,24 +475,39 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
@Override @Override
public void run() { public void run() {
OkHttpClient client = new OkHttpClient().newBuilder() OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.build(); .build();
MediaType mediaType = MediaType.parse("text/plain"); MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM) RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("path", "/仁武氯乙烯廠製造一課/3_SOP落實度查核/DA") .addFormDataPart("path", "/仁武氯乙烯廠製造一課/1_SOP導讀")
.addFormDataPart("create_parents", "flase") .addFormDataPart("create_parents", "false")
.addFormDataPart("overwrite", "true") .addFormDataPart("overwrite", "true")
.addFormDataPart("file", "IMG_20200528_144512.jpg", .addFormDataPart("file","/C:/Users/PCKing/Pictures/356154.jpg",
RequestBody.create(MediaType.parse("application/octet-stream"), RequestBody.create(MediaType.parse("application/octet-stream"),
new File("/storage/emulated/0/DCIM/Camera/IMG_20200528_144512.jpg"))) new File("/C:/Users/PCKing/Pictures/356154.jpg")))
.build(); .build();
Request request = new Request.Builder() Request request = new Request.Builder()
.url("https://fpcrtpms.synology.me:5001/webapi/entry.cgi?api=SYNO.FileStation.Upload&method=upload&version=2") .url("https://fpcrtpms.synology.me:5001/webapi/entry.cgi?api=SYNO.FileStation.Upload&method=upload&version=2&_sid=")
.method("POST", body) .method("POST", body)
.build(); .build();
try { try {
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
} catch (IOException e) {
e.printStackTrace();
}
// Call call = client.newCall(request);
// call.enqueue(new Callback() {
// @Override
// public void onFailure(@NotNull Call call, @NotNull IOException e) {
// Log.e("error", "" + e.getMessage());
// }
//
// @Override
// public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
// Log.e("response", response.body().string());
// }
// });
try {
Response response = client.newCall(request).execute();
Log.e("response", response.body().string()); Log.e("response", response.body().string());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment