Last active
September 1, 2020 08:13
-
-
Save Ahmedbadereldin/6ceda0360da3a2a5f702c41edf7757d4 to your computer and use it in GitHub Desktop.
upload file with AndroidNetworking
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
Map<String, File> multiPartFileMap = new HashMap<>(); | |
if (!PathHolder.equals("")) { | |
multiPartFileMap.put("attachment", new File(PathHolder)); | |
} | |
Map<String, String> parames = new HashMap<>(); | |
parames.put("name", name); | |
parames.put("email", email); | |
parames.put("message", details); | |
parames.put("subject", subject); | |
AndroidNetworking.upload(URLs.CONTACT) | |
.addMultipartFile(multiPartFileMap) | |
.addQueryParameter(parames) | |
.addHeaders(FamousFunction.getHeaders(this)) | |
.setTag("Contact With Us") | |
.setPriority(Priority.HIGH) | |
.setExecutor(Executors.newSingleThreadExecutor()) | |
.build() | |
.setUploadProgressListener((bytesUploaded, totalBytes) -> { | |
// do anything with progress | |
}) | |
.getAsJSONObject(new JSONObjectRequestListener() { | |
@Override | |
public void onResponse(JSONObject response) { | |
} | |
@Override | |
public void onError(ANError error) { | |
} | |
}); | |
public static Map<String, String> getHeaders(Context context) { | |
Map<String, String> headers = new HashMap<>(); | |
headers.put("Content-Type", "application/x-www-form-urlencoded"); | |
headers.put("Accept-Language", sharedPrefrences.getLanguage(context)); | |
headers.put("Authorization", sharedPrefrences.getApiToken(context)); | |
return headers; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment