Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timob 9797: Android: HTTP Post will save a photo at Internal phone storage #2498

Merged
merged 8 commits into from
Jul 10, 2012
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public class TiHTTPClient
private boolean autoRedirect = true;
private Uri uri;
private String url;
private ArrayList<File> tmpFiles;

protected HashMap<String,String> headers = new HashMap<String,String>();

Expand Down Expand Up @@ -953,7 +954,9 @@ public int addTitaniumFileAsPostData(String name, Object value)
FileOutputStream fos = new FileOutputStream(tmpFile);
fos.write(blob.getBytes());
fos.close();


tmpFiles.add(tmpFile);

FileBody body = new FileBody(tmpFile, mimeType);
parts.put(name, body);
return blob.getLength();
Expand Down Expand Up @@ -1025,7 +1028,7 @@ public void send(Object userData) throws MethodNotSupportedException
HashMap<String, Object> data = (HashMap) userData;
boolean isPostOrPut = method.equals("POST") || method.equals("PUT");
boolean isGet = !isPostOrPut && method.equals("GET");

// first time through check if we need multipart for POST
for (String key : data.keySet()) {
Object value = data.get(key);
Expand All @@ -1044,6 +1047,7 @@ public void send(Object userData) throws MethodNotSupportedException
}

boolean queryStringAltered = false;
tmpFiles = new ArrayList<File>();
for (String key : data.keySet()) {
Object value = data.get(key);
if (isPostOrPut && (value != null)) {
Expand Down Expand Up @@ -1239,6 +1243,21 @@ public void progress(int progress) {
Log.e(LCAT, "HTTP Error (" + t.getClass().getName() + "): " + msg, t);
sendError(msg);
}

deleteTmpFiles();
}
}

private void deleteTmpFiles()
{
if (tmpFiles != null && tmpFiles.size() > 0) {
for (File tmpFile : tmpFiles) {
tmpFile.delete();
}
}
if (tmpFiles != null) {
tmpFiles.clear();
tmpFiles = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we just test if tmpFiles is null OR empty. If this is true then just return.
Otherwise iterate through the files and delete each one. Once this loop is done
just null out tmpFiles (we don't need to clear since it will get GC'ed).

}
}

Expand Down