image path in ng file upload in angular - angularjs

After uploading the image using ng-file-upload to https://angular-file-upload-cors-srv.appspot.com/upload
,I get in response only the image name.
Now, if I want to render the image in html
<img ng-show="createRecipeForm.file.$valid" src="{{response.filename}}" class="img-rounded" height="100">
or
<img ng-show="createRecipeForm.file.$valid" ngf-thumbnail="{{imageArray[$index]}}" class="img-rounded" height="100">
How do I get my image here? I am using this for demo purpose and need to get it from my local computer only for now.
I see can not give path to a drive on computer here for src.
So, how do I render the image in html given that I have the file name.

If you are storing the file using a web server, you should have access to the relative path of the server to use before filename in src="{{response.filename}}"
Check where in the folder structure you are storing them, then you can try: (e.g.)
src="/AppData/{{response.filename}}"

Related

How can i download a sample xlsx file from public resource folder in React js

I'm trying to download a sample xlsx file from public folder in React js in the following way
<a
href={process.env.PUBLIC_URL + "/my-file.xlsx"}
download={"my-file.xlsx"}
>
Download file
</a>
i am stuck at this. downloading this way works locally, but when deployed to public, it fails and instead downloads just an empty corrupted file. Any ideas on that ?
Why the file is being corrupted on the server, although it works fine locally?
you should use relative path of file for href,
ex: href={"../../assets/files/my-file.xlsx"}
and dont do this "download={"my-file.xlsx"}"
instead write download={true} or only download

React Dropzone: Image files preview issue

I upload image file with previewing it in react dropzone. However, after uploading, the file is successfully uploaded (I can see it in console) but sometimes the image file is previewed and sometimes the same image file give error like:
GET blob:http://localhost:3000/438716d3-2317-438b-9d1e-eb7bc5e6149f net::ERR_FILE_NOT_FOUND
https://i.stack.imgur.com/AwjI9.png
I had this issue and the solution was to use URL.createObjectURL in the image src when displaying the image file from Dropzone.
e.g
<img src={URL.createObjectURL(file)} alt={file.name} />
Hopefully this helps someone else.

How to use an image in react imported from localhost

So i'm working on a react project and i want to use an image which is stored in my computer
i made the following code
<img src='my_image.png'/>
however it doesn't show in the browser as shown below
see image
upload your images in your public folder then access it
eg:public/images/p1.png
<img src='images/p1.png'/>
https://codesandbox.io/embed/amazing-bouman-x3mnr?fontsize=14&hidenavigation=1&theme=dark

Cannot load images from public folder

I store images in public folder, image name is a number from 1 to Image quantity, so I can get image with
<img
ref={this.imageRef}
src={process.env.PUBLIC_URL + `/images/${this.props.index}.jpeg`}
alt={`image #${this.props.index}`}
/>
When I run it on my local npm server images are rendered correclty so I can see them, but when I try to open my gallery from my web site deployed with AWS Amplify, they are not loaded, I see only image alt and image logo.
You can check it out at https://www.diamondcoring.ru/gallery
What's wrong with it ?
I don't know why, but the problem was in file extension .jpeg - it is not handled. .jpg or .png work fine

Angular JS using Grunt: Display images from local folder using relative path from JSON

So I am using a JSON that returns a lot of data about the user including pictures. The problem I am facing is that I believe the relative path to the images folder is correct however for some reason it is saying in ng-source="relativePath" instead of the image. The only conclusion I can come to is either the path is wrong or there is some sort of import I must do for the images to be used in the project.
<div ng-repeat="results in userInfo.images">
<figure class="img">
<img data-ng-source="{{results.imageUrl}}" ng-alt="{{results.name}}" ng-title="{{results.name}}" />
</figure>
</div>
I have tried source, ng-source, and data-ng-source. When I view in console and on the html for image src it shows the relative path /images/profilePicture.png.
My project has the following structure:
Repositry Name
app
css
home
home.module.js
home.tpl.html
images
profilePicture.png
js
resources
app.js
index.html
Using best practices the index.htlm is the container for the single page application. We are using the home.tpl.html page that is injected into the index.html container page.
I have tried switching the path to go directly from index.html -> /images/profilePicture.png as well as from home.tpl.html -> ../images/profilePicture.png.
I could not find any posts relevant to my situation but I believe perhaps you need an app.use or some sort of injection method to add the folder of images to be able to be used?
Note: I am not sure if this is helpful however when I run grunt build instead of serve I check the dist folder and the image folder does in fact have all of the images.
Change your <img data-ng-source declaration to just use ng-src:
<img ng-src="{{results.imageUrl}}" ng-alt="{{results.name}}" ng-title="{{results.name}}" />
More details at w3schools: ng-src

Resources