Easiest way to convert a Blob into a byte array

the mySql blob class has the following function : blob.getBytes use it like this: //(assuming you have a ResultSet named RS) Blob blob = rs.getBlob(“SomeDatabaseField”); int blobLength = (int) blob.length(); byte[] blobAsBytes = blob.getBytes(1, blobLength); //release the blob and free up memory. (since JDBC 4.0) blob.free();

Angular: How to download a file from HttpClient?

Blobs are returned with file type from backend. The following function will accept any file type and popup download window: downloadFile(route: string, filename: string = null): void{ const baseUrl=”http://myserver/index.php/api”; const token = ‘my JWT’; const headers = new HttpHeaders().set(‘authorization’,’Bearer ‘+token); this.http.get(baseUrl + route,{headers, responseType: ‘blob’ as ‘json’}).subscribe( (response: any) =>{ let dataType = response.type; let … Read more

Retrieve large blob from Android sqlite database

You can read large blobs in pieces. First find out which ones need this treatment: SELECT id, length(blobcolumn) FROM mytable WHERE length(blobcolumn) > 1000000 and then read chunks with substr: SELECT substr(blobcolumn, 1, 1000000) FROM mytable WHERE id = 123 SELECT substr(blobcolumn, 1000001, 1000000) FROM mytable WHERE id = 123 … You could also compile … Read more

How to download image in reactjs?

Came across this SO trying to figure out how to download a png image and found that the other answer didn’t quite do it for me as the downloaded file couldn’t be opened. Needed to use arraybuffer to convert the image. Here’s the code that worked. function App() { const download = e => { … Read more