- Forum posts: 1
Mar 30, 2017, 6:53:40 AM via Website
Mar 30, 2017 6:53:40 AM via Website
So I am testing methods to upload an image to a php server. One of the methods was to convert the image to a Base64 String and upload it and then decode it when needed. When I uploaded a picture I noticed that there was a difference in the codes. Some spaces were missing and some next lines were misplaced. Before I send the string to the server the string is okay and then it goes through a _POST
command in the php file and then it is inserted into the database using INSERT INTO
. I suspect that the header that I use changes the string. the header is /x-www-form-urlencoded
. I tried using /json
but if the json object is converted to string it changes the original string. So what header do I need to use so the string won't change. Or is there another method to upload a pic to a MySQLi server.
This is the method I use to upload the string to the server:
ImageString = getStringImage(bitmap);
String ImageUploadString="image="+ImageString;
final OkHttpClient client = new OkHttpClient();
MediaType contentType = MediaType.parse("application/x-www-form-urlencoded; charset=utf-8");
RequestBody body = RequestBody.create(contentType, imageUploadString));
Request request = new Request.Builder().url(uploadURL).post(body).build();
Response response = null;
try {
response = client.newCall(request).execute();
} catch (IOException e) {
e.printStackTrace();
}
try {
String json = response.body().string();
} catch (IOException e) {
e.printStackTrace();
}
— modified on Mar 30, 2017, 6:54:31 AM