Last active
August 29, 2015 14:28
-
-
Save fabdarice/a4006a97171cc415892e to your computer and use it in GitHub Desktop.
SENDING IMAGE ENCODE BASE64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void AddNewImage() { | |
String baos = GetByteArray(); | |
MultipartTypedOutput multipartTypedOutput = new MultipartTypedOutput(); | |
multipartTypedOutput.addPart("login", new TypedString(credential.getUsername())); | |
multipartTypedOutput.addPart("mobile_upload_file", new TypedString("data:image/jpeg;base64,"+baos)); | |
SetNewImage(multipartTypedOutput); | |
} | |
public String GetByteArray() { | |
File f = getTempFile(); | |
byte[] bytes = fileToByteArray(f.getPath()); | |
return Base64.encodeToString(bytes, 0); | |
} | |
private void SetNewImage(MultipartTypedOutput model) | |
{ | |
progressDialog = ProgressDialog.show(this, "", | |
getString(R.string.loading)); | |
Callback cb = new Callback<ChallengesModel>() { | |
@Override | |
public void success(ChallengesModel model, | |
Response response) { | |
Intent intent = new Intent(); | |
DeleteTempFileIfExists(); | |
setResult(Activity.RESULT_OK, intent); | |
finish(); | |
} | |
}; | |
ApiManager.getService().CreateImage(model, cb); | |
} | |
public static ImageService getService() { | |
if(api == null) | |
{ | |
OkHttpClient okHttpClient = new OkHttpClient(); | |
okHttpClient.networkInterceptors().add(new MyOkHttpInterceptor()); | |
OkClient okClient = new OkClient(okHttpClient); | |
api = new RestAdapter.Builder() | |
.setEndpoint(API_URL) | |
.setClient(okClient) | |
.setLogLevel(LogLevel.FULL) | |
.build() | |
.create(ChallfieService.class); | |
} | |
return api; | |
} | |
public interface ImageService { | |
@POST("/api/image/create") | |
void CreateImage(@Body MultipartTypedOutput userModel, Callback<ChallengesModel> cb); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment