Commit 8ab0f363 authored by Klaus Wölfel's avatar Klaus Wölfel

ERP5Storage: Add range and blob support

parent c73d13c1
...@@ -288,7 +288,21 @@ ...@@ -288,7 +288,21 @@
}); });
}; };
ERP5Storage.prototype.getAttachment = function (id, action) { ERP5Storage.prototype.getAttachment = function (id, action, options) {
var transaction,
type,
start,
end;
if (options === undefined) {
options = {};
}
start = options.start || "0";
end = options.end || "";
if (start > end) {
throw new jIO.util.jIOError("_start is greater than _end",
400);
}
if (action === "view") { if (action === "view") {
if (this._default_view_reference === undefined) { if (this._default_view_reference === undefined) {
...@@ -329,6 +343,10 @@ ...@@ -329,6 +343,10 @@
.push(function () { .push(function () {
return jIO.util.ajax({ return jIO.util.ajax({
"type": "GET", "type": "GET",
"dataType": "blob",
"headers": {
Range: "bytes=" + start + "-" + end
},
"url": action, "url": action,
"xhrFields": { "xhrFields": {
withCredentials: true withCredentials: true
...@@ -336,12 +354,20 @@ ...@@ -336,12 +354,20 @@
}); });
}) })
.push(function (evt) { .push(function (evt) {
var result = JSON.parse(evt.target.responseText); var content_type = evt.target.getResponseHeader("Content-Type");
result._id = id; if (content_type === "application/json") {
return new Blob( return jIO.util.readBlobAsText(evt.target.response)
[JSON.stringify(result)], .push(function (event) {
{"type": evt.target.getResponseHeader("Content-Type")} var result = JSON.parse(event.target.result);
); result._id = id;
return new Blob(
[JSON.stringify(result)],
{"type": content_type}
);
});
} else {
return evt.target.response;
}
}); });
} }
throw new jIO.util.jIOError("ERP5: not support get attachment: " + action, throw new jIO.util.jIOError("ERP5: not support get attachment: " + action,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment