I'm trying to store audio files in google app engine's blobstore and play them in a browser. The problem I'm running into is that the data I'm getting in the browser is the actual mp3 data. I was expecting to get a url to play the mp3 in the blobstore. So, my question is, what do I need to change to get a url to play the blob instead of the audio data?
Here is my server side handler.
class ServeBlobHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self):
user = users.get_current_user()
query = db.GqlQuery("SELECT * FROM AudioData Where userId = :1", user.user_id())
results = query.fetch(limit=300)
for dStoreEntry in results:
entityBlobInfo = dStoreEntry.audioBlob
self.send_blob(entityBlobInfo)
This is the client side.
$.ajax({
url : '/serve_blob/audio/',
type : 'GET',
dataType : 'text',
success : function(data) {
alert('GET, audio data : \n '+ data );
}
});
The URL of the page that you're currently fetching the data from is the URL of the MP3. You'll need to use a web-based player of some sort to play it.
What Content-type header does your browser get for mp3 request? I'm guessing it's application/octet-stream
See what Blobstore docs say about upload:
If you don't specify a content type, the Blobstore will try to infer it from the
file extension. If no content type can be determined, the newly created blob is
assigned content type application/octet-stream
Go to GAE admin pages and check Blob Viewer to see under what content type was assigned to your mp3 files.
Get JPlayer - http://www.jplayer.org/
And then your example should work fine. We use it with appengine blobstore in java and it's great. The url from the blobstore will work in jplayer.
You can also set cache headers on your blob urls if you rewrite them to remove any query parameters and save yourself the costs of serving each stream.
Related
I am using active storage in my Rails application. The frontend is on React. I am uploading an image via react uploader and sending that image to the backend API where I am storing it to S3 bucket using active storage.
This is the API that handles the image:
if image.attached?
opts = ImageUploader.resize_to_fill(blob: image.blob, width: 100)
variation = ActiveStorage::Variation.new(combine_options: opts)
variant = ActiveStorage::Variant.new(image.blob, variation)
return rails_representation_url(variant, only_path: true)
end
This returns the path in the following format:
/rails/active_storage/representations/...../file_name.png
This works all fine when I use this path inside the application, but I want to send this image in email, there the image breaks as the src attribute can not read this path. If I append http://localhost:3000 manually in the email through dev tools, I am able to see the image then.
Weirldy, in the email, I also see the path appended with http by itself like below:
http:/rails/active_storage/representations/...../file_name.png
I did a workaround and gave only_path to false. This way I was able to get back the complete URL but in the email I got duplicate http written somehow.
Desired Result:
Either the email also appends the host_url along the protocol or removes the http also so that I am able to pass the complete valid URL.
If there is a way to alter the api and somehow get the s3 endpoint directly that would really really work but I am not sure how to do so. It would return the url like this: //{bucketName}/uploads/file/id/image.jpeg
Any help please!
I used a voice recorder in my application, the voice data contains a blobUrl, that I want to send that url to server for downloading it, but it is not a normal url. is there any way to convert my blob url of audio to a normal url?
blob:http://localhost:3001/dfafdba3-24f4-4f36-b9d8-13f4d9634acc
this might be what you're looking for:
https://stackoverflow.com/a/71885435/11483674
In summary: you extract the data from your browser's blobUrl, make a file out of that and send it over a request to your backend.
i am building a web app using angularjs and am using firebase as my database and storage.
my issue is that i am trying to get a .txt file from my storage and display it in the browser, but whenever i make a request using the download url that i got using the firebase sdk i get a cors error.
i am authenticated in firebaseAuth and i have already been able to download images via the 'src' attribute.
this is my request:
$http({
url: url,
method: 'GET'
}).then(function(data){
console.log(data);
}).catch(function(e){
console.log(e)
});
I don't want to override the cors options if i don't have to. does anyone know how i can do this?
I am using firebase hosting to host the site, which shares the same url as my firebase storage
OK.
Thanks Mike Macdonald for your comment.
I'll just do what it says in the other thread you sent me
I followed this post and got the example code uploading a Blobstore object.
Is it possible to store arbitrary data in GAE Golang Blobstore?
However the content-type is set to application/octet-stream
Does anyone have any idea how I would go about modifying that code to send a image/jpg content-type?
I am storing a file in Google App Engine using Google Cloud Storage. The file is loaded fine but the serve returns a file interpreted as a binary not as the original mime type. You'll find hereafter the code. Has anyone an idea of what is happening ?
I. Store file
GSFileOptionsBuilder optionsBuilder = new GSFileOptionsBuilder()
.setBucket(BUCKET_NAME)
.setKey(objectId)
.setAcl("project-private")
.setMimeType(mimeType)
.setContentDisposition("attachment;filename "+item.getName());
II. Serve file
blobKey = blobstoreService.createGsBlobKey("/gs/"+BUCKET_NAME+"/"+ fileName);
blobstoreService.serve(blobKey, resp);
III. Difference with serving a file in the blobstore
I had a piece of code which used to work. The problem is that apparently the BlobInfo object is only for objects stored in the blobstore and not in the Google Cloud Storage
BlobInfo blobInfo = blobInfoFactory.loadBlobInfo(blobKey);
resp.setContentLength(new Long(blobInfo.getSize()).intValue());
resp.setHeader("content-type", blobInfo.getContentType());
resp.setHeader("content-disposition", "attachment; filename=" +
blobInfo.getFilename());
blobstoreService.serve(blobKey, resp);
Any help is very welcome !
Thanks,
Hugues
Because you're serving the blob yourself, using the blob serving service, it's up to you to set all the HTTP headers, including the content type, correctly. If you want to use the content type of the stored object, you should fetch it and set it in the headers yourself.
Alternatively, you could link directly to the object's path in Google Storage, in which case it will be served by the Google Storage infrastructure, with the correct mimetype.