0

I need to implement a progressbar showing uploading a video, but i dont find where i get the progress while uploading. Here is my code:

ServiceGenerator.class

public class ServiceGenerator {

    public static final String API_BASE_URL = "url";

    private static RestAdapter.Builder builder = new RestAdapter.Builder()
            .setEndpoint(API_BASE_URL)
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .setClient(new OkClient(new OkHttpClient()));

    public static <S> S createService(Class<S> serviceClass) {
        RestAdapter adapter = builder.build();
        return adapter.create(serviceClass);
    }
}

FileUploadService.class

public interface FileUploadService {
    @Multipart
    @POST("/")
    void upload(@Part("myfile") TypedFile file,
                @Part("hash") String hash,
                Callback<String> cb);
}

MainActivity.class

 FileUploadService service = ServiceGenerator.createService(FileUploadService.class);
                TypedFile typedFile = new TypedFile("multipart/form-data", new File(realPath));
                String hash = "JZzdFypunqDS5Ug";

                service.upload(typedFile, hash, new Callback<String>() {
                    @Override
                    public void success(String s, Response response) {
                        Log.e("Upload", "success");
                    }

                    @Override
                    public void failure(RetrofitError error) {
                        Log.e("Upload", "error");
                    }
                });
moodle
  • 149
  • 1
  • 1
  • 10
  • You will probably want to look into Interceptors https://github.com/square/okhttp/wiki/Interceptors – David Medenjak Dec 04 '15 at 09:09
  • it uses retrofit <=1.8 , but here is use 1.9 – moodle Dec 04 '15 at 09:19
  • 1
    For progress with Retrofit < 2 look here: https://github.com/square/retrofit/issues/431 – david.mihola Dec 04 '15 at 10:03
  • It is not supported, since length is not known by Retrofit before sending file. – Jemshit Dec 12 '15 at 12:23
  • Progress for Retrofit 1 http://stackoverflow.com/questions/23348812/android-retrofit-onprogressupdate-for-showing-progress-notification/24772058#24772058 Progress for Retrofit 2 http://stackoverflow.com/questions/33338181/is-it-possible-to-show-progress-bar-when-upload-image-via-retrofit-2#33384551 – Deni Erdyneev Oct 20 '16 at 04:10

0 Answers0