0

I am uploading video,it is uploaded with out header request, i tried with request property,its not working.but i don't know how to add header with this code. I need to send video with api key in header. i am asking api key in header request,not in authorization.

public int uploadFile(final String sourceFileUri) {
                HttpURLConnection conn = null;
                DataOutputStream dos = null;
                String lineEnd = "\r\n";
                String twoHyphens = "--";
                String boundary = "*****";
                String mm = "JJHJJHJHHKKJJKHHKHHKHKKKHHKHK";
                int bytesRead, bytesAvailable, bufferSize;
                byte[] buffer;
                int maxBufferSize = 1 * 1024 * 1024;
                File sourceFile = new File(sourceFileUri);
                if (!sourceFile.isFile()) {
                    return 0;
                } else {
                    try {
                        FileInputStream fileInputStream = new FileInputStream(sourceFile);
                        URL url = new URL("https:/fffs.co.in/ghh_site/api/video");
                        Log.d("WebService", "url=" + url);
                        // Open a HTTP connection to the URL
                        conn = (HttpURLConnection) url.openConnection();
                        conn.setDoInput(true); // Allow Inputs
                        conn.setDoOutput(true); // Allow Outputs
                        conn.setUseCaches(false); // Don't use a Cached Copy
                        conn.setRequestMethod("POST");
                        conn.setRequestProperty("Connection", "Keep-Alive");
                        conn.setRequestProperty("ENCTYPE", "multipart/form-data");
                     //  conn.setRequestProperty("X-API-KEY=","GHJJHGJGHGHJGHHJGJGHGGJ");
                     //  conn.getHeaderFieldDate("X-API-KEY", Long.parseLong(mm));
                        conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
                        conn.setRequestProperty("video_upload", filepathUrl1.getName());

                    } catch (MalformedURLException ex) {
                        ex.printStackTrace();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    Log.d("ssk", "result" + result);
                    return serverResponseCode;
                } // End else block
            }

The above code has no header,hw to add this in multipart?

Raja Sankar
  • 39
  • 10

0 Answers0