Answer the question
In order to leave comments, you need to log in
Problem with uploading audio to VK?
You need to upload an audio file to VK. For this I use Kate VK API. It looks like this:
public void uploadAudioToWall(String filePath, String url){
try {
HttpClient client=new DefaultHttpClient();
HttpPost httpPost=new HttpPost(url);
MultipartEntity albumArtEntity = new MultipartEntity();
httpPost.addHeader("Content-type", "multipart/form-data; boundary=*****");
albumArtEntity.addPart("file", new FileBody(new File(filePath)));
httpPost.setEntity(albumArtEntity);
HttpResponse response=client.execute(httpPost);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
StringBuilder builder = new StringBuilder();
for (String line; (line = reader.readLine()) != null;) {
builder.append(line).append("\n");
}
JSONObject photoObject = new JSONObject(builder.toString());
Log.e("FILE", filePath);
Log.e("NEW URI", url);
Log.e("res", photoObject.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
String upurl = api.getAudioUploadServer();
uploadAudioToWall(path, upurl);
{
"redirect":"http:\/\/vk.com\/audio.php?act=done_add&mid=120146182&aid=0&gid=0&server=611229&audio=%7B%22error%22%3A-2%7D&hash=7343021a24966d4e0fe12e485d53aa3d",
"server":611229,
"audio":"%7B%22error%22%3A-2%7D",
"hash":"7343021a24966d4e0fe12e485d53aa3d"
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question