2

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.

1 Answer 1

2

Those methods are not yet implemented; check source for request and response.

export class Request {
  // TODO: support URLSearchParams | FormData | Blob | ArrayBuffer
}
export class Response {
  // TODO: Support ArrayBuffer, JSON, FormData, Blob
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.