Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.

Blob / Upload Detection #11

Merged
merged 3 commits into from
Jul 5, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions debug/abaaso.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,8 @@ if (typeof global.abaaso === "undefined") global.abaaso = (function () {
fail = function (arg) { uri.fire("failed" + typed, arg); },
timeout = function (arg) { uri.fire("timeout" + typed, arg); },
doc = (typeof Document !== "undefined"),
ab = (typeof ArrayBuffer !== "undefined");
ab = (typeof ArrayBuffer !== "undefined"),
blob = (typeof Blob !== "undefined");

if (type === "delete") uri.once("afterDelete", function () { cache.expire(this); });

Expand All @@ -767,6 +768,7 @@ if (typeof global.abaaso === "undefined") global.abaaso = (function () {
if (typeof xhr.onerror === "object") xhr.onerror = fail;
if (typeof xhr.ontimeout === "object") xhr.ontimeout = timeout;
if (typeof xhr.onprogress === "object") xhr.onprogress = function (e) { uri.fire("progress" + typed, e); };
if (typeof xhr.upload.onprogress === "object") xhr.upload.onprogress = function (e) { uri.fire("progressUpload" + typed, e); };

try {
xhr.open(type.toUpperCase(), uri, true);
Expand All @@ -780,11 +782,11 @@ if (typeof global.abaaso === "undefined") global.abaaso = (function () {
if (payload.hasOwnProperty("xml")) payload = payload.xml;
if (doc && payload instanceof Document) payload = xml.decode(payload);
if (typeof payload === "string" && /<[^>]+>[^<]*]+>/.test(payload)) contentType = "application/xml";
if (!(ab && payload instanceof ArrayBuffer) && payload instanceof Object) {
if (!(ab && payload instanceof ArrayBuffer) && !(blob && payload instanceof Blob) && payload instanceof Object) {
contentType = "application/json";
payload = json.encode(payload);
}
if (contentType === null && ab && payload instanceof ArrayBuffer) contentType = "application/octet-stream";
if (contentType === null && ((ab && payload instanceof ArrayBuffer) || (blob && payload instanceof Blob))) contentType = "application/octet-stream";
if (contentType === null) contentType = "application/x-www-form-urlencoded; charset=UTF-8";
}

Expand Down