I am uploading images to Cloud Storage using the Java Client Library Images are uploaded to Bucket but when I am trying to access them, a Black screen is displaying in browser. So, I dug into this to check the type of the Image after it is uploaded into Cloud Storage.
I uploaded the image I downloaded from the cloud storage to Check File Type .com and it is showing file type as data and MIME/TYPE as application/octet-stream instead of image
So , I uploaded the original image of the same from my PC and it is perfectly showing the image type as image/jpeg
Here is the code I have written using the Java client library.
HTML Form to handle the upload
<form action="/through" method="post" enctype="multipart/form-data">
<h3>Uploading File through App Engine instances to cloud storage</h3>
<label>Enter Your Team Name</label><br>
<input type="text" name="TeamName" ><br><br>
<label>Upload Team Logo</label><br>
<input type="file" name="teamLogo" required="required"><br><br>
<input type="submit" value="Upload Team Logo">
</form>
Java code to Upload the Image
InputStream input = request.getInputStream();
ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
try {
int read = input.read();
while(read != -1) {
byteArrayStream.write(read);
read = input.read();
}
catch (IOException e){
//Handle Exception
}
byte[] fileBytes = byteArrayStream.toByteArray();
Storage storage = null;
try {
FileInputStream credentialsStream = new FileInputStream("JSONFile");
Credentials credentials = GoogleCredentials.fromStream(credentialsStream);
storage = StorageOptions.newBuilder().setCredentials(credentials).setProjectId("myProjectID").build().getService();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BlobId blobId = BlobId.of(BUCKET_NAME, USER_NAME+"TeamLogo.jpg");
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("image/jpeg").build();
Blob blob = storage.create(blobInfo, fileBytes);
Why Cloud Storage is not able to detect the type of image properly? It is having adverse effects on other parts of my application where I want to display the same images.
UPDATE
In Console for the same object, Content-Type is showing as image/jpeg



