Want to shorten image url in asp.net
My Code in Asp.net is
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(Server.MapPath("images/") + filename);
And It store url in my Database as
C:\Users\A\Documents\Visual Studio 2012\WebSites\WebSite1\images\IMG_20190802_114524.jpg
I want to shorten my image url in Mysql DB
/image/imagename
The Concept of saving file URL in DB is you have to save relative path only. In your case
let spouse:
C:\Users\A\Documents\Visual Studio 2012\WebSites\WebSite1\images\IMG_20190802_114524.jpg
This part is same for all images so why you are saving this in db make a constant and asign this path.
C:\Users\A\Documents\Visual Studio 2012\WebSites\WebSite1\images\
Now you have to save only file name in db.
IMG_20190802_114524.jpg
So when you want to access image concatenate constant value and file name and you get image.
Hope this'll help you.
Related
I'm a junior dev trying to build a portfolio site and want to upload a pic of me that is already downloaded on my PC. When I type in an src of an image that exists somewhere online it clearly appears on my live server but when I insert the src of an image existing somewhere within my PC's local drives it doesn't appear. Is it that I have to upload this image somewhere online (e.g. google drive) and then type in its new src or is there a way to upload offline images?
Hope someone can help!
Create a folder called assets in your project and add all images and any other files you may need. Then add the path to your image in src
there are some options to do it.
The more preferable is creating a folder let's say Src or Images. Then download any images into the folder using classes from a namespace System.IO (Path, Directory, ...). But be sure that your image names+extension are unique. Also, you can store in a DB file name and path the related file on your server and userId to be sure who added the file.
Another option is to store byte arrays in DB. Adding action for returning your file
public async Task<AcitonResult> GetImage(int id)
{
byte[] imgBytes = await GetImageFromDbById(id);
if (imgBytes == null)
return NotFound();
return File(imgBytes, "image/jpg");
}
Asking an image
<img src="/**YourControllerName**/GetImage/**#imageId**">
I want to send an image to MySQL blob feild using node.js and use Angular to display that blob as an image.
Any ideas how to do it?
It would be better if you upload image file on server and get its path and store that path in MySQL database.
for example if user wants to upload test.jpg
on server save it like : server/images/test.jpg
then insert saved path to MySQL
and on front-end retrieve image path and bind to src property of image tag.
saving blobs to database will result in slow response when you will fetch records.
you can see more details here: https://blog.jscrambler.com/implementing-file-upload-using-node-and-angular
I am working in BIDS (SSIS 2008). I have a flat file connection to a pip-delimited file with a .pip extension. The file name can change significantly. However, it will always have the word 'stuff' in the file name. For example, a valid file name is 123_x_stuff_456.pip. How can I set up a dynamic connection for this dynamic file name?
So far, I have created a variable to hold the UNC path of the file (e.g., \drive1\folder1). My next step (I think) is to create an expression in the flat file connection manager to concatenate the file name to the UNC path variable. The problem I am running into is that I can't specify wildcards for the text before and after the token that I'm search for in the filename. For example, in SSMS, I would concatenate the UNC path variable to something like '%stuff%. For all tutorials that I've seen on this, they always follow a prescribed file name format, whereas, in my situation, the format will always be different (other than the token that it will always contain). How do I go about this?
How can I get full path of selected file.
for example I selected logo.png
it should get c:\user\admin\desktop\logo.png
String im = request.getParameter("image");
InputStream inputStream = new FileInputStream(new File(im));
pstmt=con.prepareStatement("Insert into items(image) values(?)");
pstmt.setBlob(1, inputStream);
This code insert to datbase it show this following error
java.io.FileNotFoundException: logo.png (The system cannot find the file specified)
(tried everything no luck)
If you are trying to do file upload to a database using JSP and Servlet the way you are doing is wrong.
You cannot get the file path from a client machine for security reasons. Even if you get the file path from client machine that file won't be available in the server, since the code runs in the server you will allways get java.io.FileNotFoundException.
Check Upload files to database (Servlet + JSP + MySQL) example for how to upload a file to MySQL database using JSP and Servlet.
I have stored an HTML file in IsolatedStorage as test.html.
In UI I have a WebBrowser component called browser. I'm using the following code to show the webpage in the browser:
browser.Navigate(new Uri("isostore:/test.html", UriKind.Absolute));
However it's giving me the prompt to search for an app in store, as if I'm trying to use LaunchUriAsync or LaunchFileAsync API.
I guess the problem is with the Uri format. What should be the correct Uri format in this case?
I have solved it, by removing 'isostore:/' prefix from the Uri string. I know that without any prefix the file path would refer to the application folder, not the isolated storage. It seems they've made an exception for the WebBrowser component.
This is what works now:
browser.Navigate(new Uri("test.html", UriKind.Relative));
C:/Data/Users/DefApps/AppData/{43F7CB8F-D4CF-425D-96BD-CD96D3FF44DC}/Local/test.html
The path above is an alternative and absolute path to the isolated storage. This string, {43F7CB8F-D4CF-425D-96BD-CD96D3FF44DC}, is unique to the app but can be set/found from within the properties folder of your visual studio project. You can also obtain it by using the following lines in the C# code:
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
String mystring = localFolder.Path;