Unable to retrieve the information from URL.createObjectURL

I'm interested in learning how to retrieve the data wrapped in URL.createObjectURL.

So, I decided to write the following code snippet.

function convertTypedArrayToURL(typedArray, mimeType) {
  return URL.createObjectURL(new Blob([typedArray.buffer], {type: mimeType}))
}
const bytes = Uint8Array.from("https://www.baidu.com/")
// const url = convertTypedArrayToURL(bytes, 'text/html');
const url = convertTypedArrayToURL(bytes, 'text/plain; charset=utf-8');

let blob = await (await fetch(url)).blob();
console.info(new Uint8Array(blob))

let ab = await (await fetch(url)).arrayBuffer();
console.info(new Uint8Array(ab))

The size of the blob or array buffer is 22, which is equal to the length of

"https://www.baidu.com/"
, however, the data within it appears to be all zeros.

Answer №1

An intArray requires integer values, so you must ensure the data is in the correct format.

For example,

const bytes = Uint8Array.from("https://www.google.com/".split('').map(v=>v.charCodeAt(0)));

or

const encoder = new TextEncoder();
const bytes = Uint8Array.from(encoder.encode("https://www.google.com/"))

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to incorporate a random test case on Codewars?

I have a function on codewars.com called getNumberLength(n). This function takes a number with different digits and should return the length of the number. For example, for the number n=2000, the function should return 4. I have already added some test c ...

Modify the background of a Div element by selecting an alternate color palette

Here is my code that changes the background of a Div on select change from a dropdown. I believe there might be a more efficient way to achieve this. Can anyone provide recommendations? Thank you for taking a look. $(document).ready(function() { $(" ...

Displaying information retrieved from an AJAX request onto a webpage

Utilizing AJAX, I am dynamically adding more articles to a list by triggering a button press. The response data from the AJAX call consists of article titles, authors, and up to three associated images. Below is the current code implementation for displayi ...

Unlock the message with Proxy Re-encryption technology

I'm completely new to encryption and am experimenting with a Node JS library called recrypt-js for Proxy Re-encryption using CryptoJS. I tried encrypting the message "test data" following the example provided, but I'm facing difficulty when tryin ...

Transferring a variable from a scriplet to JSP with the issue of a null

Seeking assistance with passing a variable from a scriptlet in one jsp to the 'calling jsp' The scenario involves assetedit.jsp posting a binary stream to upload.jsp. However, despite the processing of the stream in upload.jsp and determination ...

How come JavaScript variables are able to persist on JQuery Mobile multi-page templates on desktop browsers, but not on mobile browsers?

My website was created using the jQuery Mobile multi-page template. While testing it on Chrome desktop, I noticed that my JavaScript variables (comics and checkedItems) retain their values when navigating between pages. However, on mobile devices, these ar ...

Utilizing a self-invoking function to incorporate JavaScript

In my role, I am responsible for managing a Content Management System (CMS) used by developers to create content that involves JavaScript. In the past, we placed the content in an iFrame for containment purposes; now, it operates as a single-page client-si ...

When a link is added, the Bootstrap drop-down button may become unresponsive

I've encountered an issue with a Bootstrap dropdown menu that I created using jQuery and Bootstrap. The links within the dropdown menu are not redirecting to the correct pages as intended. Can someone help me identify what mistake I might be making he ...

Implementing TypeScript with styled components using the 'as' prop

I am in the process of developing a design system, and I have created a Button component using React and styled-components. To ensure consistency, I want all my Link components to match the style and receive the same props as the Button. I am leveraging t ...

Guide to transferring a PHP variable from a loop and converting it into a JavaScript variable

I am having an issue with accessing specific row values in a while loop that displays data from a mysql table into a table. Each row has a button to send data via ajax to another PHP page for insertion into another table. However, since I am outside of the ...

Treating Backbone Collection as an object instead of an array

Currently, I am working on incorporating nested comments using both Backbone and Rails. In my current setup on the server side, comment models are utilized to store the unique identifier parent_comment_id (assuming they have one). Whenever the application ...

AngularJS service $http is not retrieving the complete SELECT query results

Every time I try to retrieve data from this table, I only get the first entry even though there are actually three entries in there. The success alert response and the page it's directing to only show the first one, so I know it's not returning a ...

Utilizing Multiple Components on a Single Page in React.js

I'm currently setting up a React main page that renders two separate components - Header and Test. render() { return ( <Header /> <Test /> ); } The Header component contains static content, while the ...

The JavaScript Discord Bot is having trouble connecting to a voice channel

I'm currently working on developing a discord bot using node.js. While I've successfully set it up to respond, I'm facing an issue with summoning it to a voice channel. Here is the snippet of code I am working with: switch (args[0]) { c ...

A messaging application powered by socket.io and the Express JS framework

I am currently learning Node.js and I am encountering an issue with using socket.id to identify logged in users on the client side using their email id and password. The verification process happens on the server side, and if successful, the user's so ...

[Assistance Needed]: Transforming Three.js coordinate systems

Is there a way to adjust the default drawing position in three.js from (0,0,0) at the center of the canvas to the actual start of the canvas? For an example, check out this code: https://jsfiddle.net/data_x/mwprgnra/8/ I am looking to shift the lines to ...

Creating a dynamic background image for the ul/li div element

As a newcomer to website development, I am currently exploring how to dynamically set images in the ul/li elements within a div. Below is a snippet of the HTML code I have been working on: <div class="results"> <ul class="row"> < ...

Validating the user's age should be at least 18 years or older to ensure their date of birth

I'm currently incorporating bootstrap-datepicker.js to gather the date of birth from a calendar. I want to prevent past dates from being selected and only allow dates in the future that are at least 18 years away to be enabled on the calendar. Any ass ...

Twitter posting unsuccessful: Issue encountered - Your current access is restricted to certain Twitter API v2 endpoints along with limited v1.1 endpoints like media post and oauth

My JavaScript app uses NPM Twit to post on Twitter. Suddenly, my bot stopped working with no explanation. It turns out that Twitter required me to switch to their new free tier and I had to delete all content from my Twitter Dev account and recreate my pro ...

Tips for updating a specific section of a Django webpage using AJAX

Currently, I am in the process of launching a website using Django. One crucial application on this site is the 'forum' which facilitates discussions among users. The discussion forum can be accessed through the URL 'XXX.com/forum/roomY&apo ...