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,13 +354,21 @@ ...@@ -336,13 +354,21 @@
}); });
}) })
.push(function (evt) { .push(function (evt) {
var result = JSON.parse(evt.target.responseText); var content_type = evt.target.getResponseHeader("Content-Type");
if (content_type === "application/json") {
return jIO.util.readBlobAsText(evt.target.response)
.push(function (event) {
var result = JSON.parse(event.target.result);
result._id = id; result._id = id;
return new Blob( return new Blob(
[JSON.stringify(result)], [JSON.stringify(result)],
{"type": evt.target.getResponseHeader("Content-Type")} {"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,
400); 400);
......
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