FileReader APIを使用する必要はありません。 file
オブジェクトを直接ストリームする方が効率的です。
var config = { headers: { 'Content-Type': undefined } };
$http.post(url, file, config)
.then(function (response) {
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
console.log("Success");
return response;
}).catch(function (errorResponse)
console.log("Error");
throw errorResponse;
});
XHR Send Methodは、彼らはBlobの単なる特殊なタイプですとfile
オブジェクトをストリーミングする方法を知っています。これにより、すべてのファイルをメモリに保存するオーバーヘッドが回避されます。
がコンテンツタイプヘッダーを設定できるように、コンテンツタイプヘッダーをundefined
に設定することが重要です。それ以外の場合、AngularJSフレームワークはコンテンツタイプapplication/json
で上書きされます。
詳細については、AngularJS $http Service API Referenceを参照してください。