Skip to content

Commit

Permalink
cleaned up old uploader code
Browse files Browse the repository at this point in the history
  • Loading branch information
mlni committed Nov 30, 2010
1 parent 1c80348 commit 12ace0c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 64 deletions.
14 changes: 6 additions & 8 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 0 additions & 56 deletions src/ee/mattijagula/mikker/upload/Uploader.java
Expand Up @@ -10,11 +10,8 @@
import org.apache.commons.httpclient.methods.multipart.PartSource;

import java.io.ByteArrayInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class Uploader {
private static final String BOUNDARY = "----WebKitFormBoundary8NHXoPOgtdmTKB7e";
Expand All @@ -37,7 +34,6 @@ private void doUpload(final byte content[], ProgressListener progressListener)
throws IOException, UploadFailedException {
HttpClient client = new HttpClient();

// PostMethod post = new PostMethod("http://localhost/~matti/recorder/upload.php");
PostMethod post = new PostMethod(ctx.getUploadUrl());

post.addRequestHeader("User-Agent", ctx.getUserAgent());
Expand Down Expand Up @@ -78,56 +74,4 @@ public InputStream createInputStream() throws IOException {
throw new UploadFailedException("Upload failed with code " + HttpStatus.getStatusText(status));
}
}

public void upload_old(byte content[]) throws IOException {
URL url = new URL(ctx.getUploadUrl());
HttpURLConnection theUrlConnection = (HttpURLConnection) url.openConnection();
theUrlConnection.setRequestMethod("POST");
theUrlConnection.setDoOutput(true);
theUrlConnection.setDoInput(true);
theUrlConnection.setUseCaches(false);

theUrlConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
if (!"".equals(ctx.getCookies()))
theUrlConnection.setRequestProperty("Cookie", ctx.getCookies());
theUrlConnection.setRequestProperty("User-Agent", ctx.getUserAgent());

DataOutputStream httpOut = new DataOutputStream(theUrlConnection.getOutputStream());

String str = "--" + BOUNDARY + "\r\n"
+ "Content-Disposition: form-data; name=\"" + ctx.getFileFieldName() + "\"; filename=\"" + ctx.getUploadFilename() + "\"\r\n"
+ "Content-Type: " + ctx.getUploadMimeType() + "\r\n"
+ "\r\n";

httpOut.write(str.getBytes());

httpOut.write(content);

KeyValuePairParser.Pair postParameters[] = ctx.getAdditionalPostParameters();
for (KeyValuePairParser.Pair pair : postParameters) {
String name = pair.key;
String value = pair.value;
httpOut.write(("\r\n--" + BOUNDARY + "\r\n").getBytes());
httpOut.write(("Content-Disposition: form-data; name=\""+ name +"\"\r\n" +
"\r\n").getBytes());
httpOut.write(value.getBytes());
}

// last one gets extra hypens at the end
httpOut.write(("\r\n--" + BOUNDARY + "--\r\n").getBytes());

httpOut.flush();
httpOut.close();

// read & parse the response
InputStream is = theUrlConnection.getInputStream();
StringBuilder response = new StringBuilder();
byte[] respBuffer = new byte[4096];
int len;
while ((len = is.read(respBuffer)) >= 0) {
response.append(new String(respBuffer, 0, len).trim());
}
is.close();
System.out.println(response.toString());
}
}

0 comments on commit 12ace0c

Please sign in to comment.