As described in the question above, I'm trying to upload a file from okhttp3 to the server.
I'm always receiving 'You did not select a file to upload' in my approach from codeIgniter part.
Here's my code
Android:
public void sendItem(File item) { Response response = null; MediaType mediaType = MediaType.parse(FileUtils.getMimeType(item)); try { RequestBody formBody = new MultipartBody.Builder().addFormDataPart("item", item.getName(), RequestBody.create(mediaType, item)).build(); Request request = new Request.Builder().url("index.php").post(formBody).build(); response = client.newCall(request).execute(); int statusCode = response.code(); // always 500 } catch (IOException e) { e.printStackTrace(); } finally { if (response != null) response.close(); } }
Server Code:
function upload(){ $config['upload_path'] = '.../assets/...'; $this->load->library('upload', $config); $this->upload->initialize($config); $media = 'item'; if (!$this->upload->do_upload($media)) { $error = array('error' => $this->upload->display_errors()); print_r($error); }else{ $stuff = $this->upload->data(); return $stuff ; } }
What am i doing wrong? Thanks!
$media
? – Kristiyan