Commit 24c79cd7 authored by Loris Croce's avatar Loris Croce
Browse files

send files not really working (bis)

parent 2b08bdf3
......@@ -90,11 +90,13 @@ public class MainActivity extends AppCompatActivity {
public void onClick(View v) {
//TODO list files in directory and send them
// TODO upload single file iter list files
sender.uploadMultipleFiles(Arrays.asList(dataLogger.getFolder()
.getFolder().listFiles()));
Log.d(TAG, "onClick: " + Arrays.asList(dataLogger.getFolder()
.getFolder().listFiles()));
//Log.d(TAG, "onClick: " + Arrays.asList(dataLogger.getFolder()
// .getFolder().list()));
try {
fileSend();
} catch (Exception e) {
e.printStackTrace();
}
}
});
......@@ -174,6 +176,7 @@ public class MainActivity extends AppCompatActivity {
public void fileSend() throws Exception {
for (File f : dataLogger.getFolder().getFolder().listFiles()) {
Log.d("FileSend", "startRecording: " + f);
sender.upload(f);
}
}
}
......@@ -12,8 +12,8 @@ import retrofit2.http.Part;
public
interface ApiConfig {
@Multipart
@POST("retrofit_example/upload_image.php")
Call uploadFile(@Part MultipartBody.Part file, @Part("file") RequestBody name);
@POST
Call uploadFile(@Part MultipartBody.Part file, @Part RequestBody name);
@Multipart
@POST("retrofit_example/upload_multiple_files.php")
Call < ServerResponse > uploadMulFile(@Part List<MultipartBody.Part> files);
......
......@@ -39,20 +39,16 @@ public final class Sender {
// Uploading Image/Video
public void uploadMultipleFiles(List<File> files) {
public void upload(File file) {
//progressDialog.show();
// Map is used to multipart the file using okhttp3.RequestBody
// Parsing any Media type file
List<RequestBody> requests = new ArrayList<>();
List<MultipartBody.Part> filesToUpload = new ArrayList<>();
RequestBody requestBody;
for (File file: files) {
requestBody = RequestBody.create(MediaType.parse("*/*"), file);
filesToUpload.add(MultipartBody.Part.createFormData("file1", file.getName(),
requestBody));
}
MultipartBody.Part fileToUpload;
RequestBody requestBody = RequestBody.create(MediaType.parse("*/*"), file);
fileToUpload = MultipartBody.Part.createFormData("file1", file.getName(), requestBody);
ApiConfig getResponse = AppConfig.getRetrofit().create(ApiConfig.class);
retrofit2.Call<ServerResponse> call = getResponse.uploadMulFile(filesToUpload);
retrofit2.Call<ServerResponse> call = getResponse.uploadFile(fileToUpload, requestBody);
call.enqueue(new retrofit2.Callback<ServerResponse> () {
@Override
public void onResponse(retrofit2.Call<ServerResponse> call, retrofit2.Response<ServerResponse> response) {
......
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