Last active
December 29, 2015 17:59
-
-
Save kaecy/7707951 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void uploadPic(HttpURLConnection connection, File name) { | |
String BOUNDARY = "--$hocuspocus"; | |
DataOutputStream output = null; | |
connection.setRequestProperty( | |
"Content-Type", | |
"multipart/form-data; boundary=$hocuspocus" | |
); | |
try { | |
output = new DataOutputStream(connection.getOutputStream()); | |
output.writeBytes(BOUNDARY + "\r\n"); | |
output.writeBytes("Content-Disposition: form-data; name=\"k\"" + | |
"\r\n\r\n\""); | |
output.writeBytes(Key + "\r\n"); | |
output.writeBytes(BOUNDARY + "\r\n"); | |
output.writeBytes("Content-Disposition: form-data; name=\"f\";" | |
+ " filename=\"" + name.getName() + "\"\r\n"); | |
output.writeBytes("Content-Type: image/jpeg" | |
+ "\r\n\r\n"); | |
int a; | |
FileInputStream file = new FileInputStream(name.getPath()); | |
while ((a = file.read()) != -1) | |
output.write(a); | |
System.out.println("File transfered"); | |
output.writeBytes(BOUNDARY + "\r\n"); | |
output.writeBytes("Content-Disposition: form-data; name=\"z\"" | |
+ "\r\n\r\n" | |
+ "poop" + "\r\n" | |
); | |
output.writeBytes(BOUNDARY + "--\r\n"); | |
System.out.println("All transfered"); | |
} catch (IOException excep){ | |
System.out.println("Error sending"); | |
} | |
try { | |
output.flush(); | |
output.close(); | |
} catch (IOException excep){} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment