P
P
Perkovec2015-04-22 22:57:17
Java
Perkovec, 2015-04-22 22:57:17

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();
    }
}

I call the function like this:
String upurl = api.getAudioUploadServer();
uploadAudioToWall(path, upurl);

The path variable stores the path to the file (for example, "/storage/emulated/0/Rec/22-41-39_21-3-2015.mp3")
In response, I get the following:
{
  "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"
}

Why does it return "audio":"%7B%22error%22%3A-2%7D" to me? Please help me find the error.
PS There is a token, the application is turned on and gets access to audio recordings.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2015-04-27
@denilenko

Could this be somehow related to the fact that VKontakte has closed the ability to upload mp3 files to the documents section?
news.softodrom.ru/ap/b21810.shtml

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question