Заливаю картинку на сервер
URL uploadUrl = new URL(API_FILES_UPLOADING_PATH);
HttpURLConnection connection = (HttpURLConnection) uploadUrl.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.writeBytes(twoHyphens + boundary + lineEnd);
outputStream.writeBytes("Content-Disposition: form-data; name=\"" +
FORM_FILE_NAME + "\"; filename=\"" + filePath + "\"" + lineEnd);
outputStream.writeBytes("Content-Type: image/jpeg" + lineEnd);
outputStream.writeBytes(lineEnd);
FileInputStream fileInputStream = new FileInputStream(new File(filePath));
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0) {
outputStream.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
outputStream.writeBytes(lineEnd);
outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
int serverResponseCode = connection.getResponseCode();
fileInputStream.close();
outputStream.flush();
outputStream.close();
if (serverResponseCode == 200) {
result = readStream(connection.getInputStream());
} else {
result = readStream(connection.getErrorStream());
}
Нормально заливалось. Но сейчас дополнительно требуется отправлять картинку с id приложения к которому она принадлежит.
пытаюсь добавить параметр так, но в ответ приходит что параметра не хватает
builder = new Uri.Builder()
.appendQueryParameter("id_app", id_app);
String query = builder.build().getEncodedQuery();
OutputStream os = connection.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(query);
Подскажите как отправить картинку с параметром