I have a component that accepts dropped files (images), and then can upload them to the server.
export class MyComp {
function save() {
let data : ArrayBuffer = this.readFile(this.file);
this.imageService.upload(data);
}
}
The service POST the data to the server as a binary content (content-type is image/png).
@Injectable()
export class ImageService {
private http: Http;
constructor(@Inject()http: Http) {
this.http = http;
}
upload(image: ArrayBuffer) {
let headers = new Headers({ 'Content-Type': 'image/png' });
//let arr = new Int16Array(image);
//let body = String.fromCharCode.apply(null, arr);
return this.http
.put('/upload', body, { headers: headers })
.map(response => response.json());
}
The problem is that I don't arrive to send binary data (ArrayBuffer). I try to send the ArrayBuffer (it sends a string "ArrayBuffer" !), to send a Int16Array (it send a lot more bytes), to convert to string... but nothing works.