I want to write one program by visual studio 2008 (C# and ASP) that has web application and windows application.
I want to get clients images in web app(upload) and store them in DB (mysql) then send these images to windows app via web service (so i new web service, not web site). But i have 2 problems:
I have 2 ways to store images in mysql, first i should have BLOB field in DB -that it takes more space-, second i should save just name of each image in DB(so have image in one folder) -in this way i don't know how get image from clients and store them in that folder-. which one? Or what other?
How (code) can i transfer image via web service(Byte[] or? ).
One of the options to transfer the image using WCF is to convert image to byte array and pass it to client. Then convert from byte[] to image on client side.
Question 1:
The images or links in DB debase is old and still unresolved. There was a microsoft white paper that came out that recommended (for SQL Server 2008, so your mileage may vary) that for images/binaries under 150k DB storage is a good compromise. If most images are over, go with links, if under, store in DB.
Question 2:
The webservice will have an http context object, so you could simply use the Response.BinaryWrite method, that takes a byte[]. You will still need to write the correct headers (for mime type etc).
For a file on disk, the simplest thing to do is use the Response.WriteFile method that takes a file path argument.
In either case, you will need to intercept this on the client and convert back to an image.
Related
I have a neural network in a jupyter notebook which I am usting as a black box for my program. The network takes an image in, makes some changes and returns an image back. I am trying to find a way to send the image and an int value from the winform into the jupyternotebook (probably as a path to it) and then return the result back to the windows forms with the ability to save it on the computer.
If it would help, the neural network is based on Keras.
I tried some guides that i have found on the internet, i will link them below, and asked a couple of teachers for help but I didn't have any results.
Here are the things I have found:
https://ndres.me/post/jupyter-notebook-rest-api/
How do you put an image file in a json object?
Call and consume Web API in winform using C#.net
https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/bb412179(v=vs.100)
You can choose an alternative way:
Using your jupyter notebook, save the Keras model, and then build a python server that listens for calls from your WinForms program.
You can start off with a few more relevant tutorials:
Training and serving ML models with tf keras
Deploying Keras models using TensorFlow Serving and Flask
Basically, what you want to do is:
Save your model's weights and graph.
Serve as server that listens for incoming requests via some protocol(HTTPRequests or RPC for instance)
Make you WinForms program call it and get the answer.
Depending on your application, you can:
Return the image as lists of lists (for instance as in RBG, you can specify the exact value of each pixel and channel)
Return a binary stream of the image (encode it and decode it)
Encode to Base64 string.
You can also explore for more options.
Eventually, now you have a service that runs in background and awaits from WinForms to call it with an image.
You can also serve it over the internet if you choose web-based protocol (Flask for instance).
I am using SQL Server and ASP.Net Core WebAPI as my backend. I want to send files to the mobile app from my server.
What is the best practice for doing this?
Send the file as a byte array. The mobile app has to write the business logic to process the file based on content type and display in the app.
OR
Convert BLOB to actual file based on file's content type and share the server path to the mobile app. The mobile app can download and display the content.
Note: When to delete the actual file stored on the server is a concern here.
Which one is the best one? Any other suggestions?
Thank in Advance.
Well, first, the file should be in your database or on your filesystem, not both. If you're going to do something like query the blob from the database, write it to the filesystem, and then return a URL to that written file, don't add it to the database at all, and simply store it on the filesystem in the first place.
Second, a byte array isn't something that has to be "converted", as the name implies, it's just raw bytes. That's what the client receives from the server regardless of the source. (In other words, if you read from the file system, the client is still getting streamed raw bytes.) The mime type the server returns along with the file tells the client how to interpret the bytes.
I am currently storing images in an SQL server database having type image. i have built an android app that retrieves these images by calling on a c# web service that fetches the image from the database, encode it in Base64 and send it to the android app. in the app level, i decode it and change it to image successfully. my concern is that this call downloads the data once and not in chunks and may result in timeouts in case of multiple images. so can anyone suggest an alternative? should i store the images as physical files and not in the database and use download manager to retrieve them? any suggestions would be helpful
I have an ASP.NET web-forms application which is integrated with a Silverlight component. The communication between the two is done using WCF services. I want to transfer data (string) from the server to Silverlight. The size of the data is guaranteed to be less than 160 KB. I have two scenarios:
I can write my data to an xml file on the server and then access it and consume it from silverlight (I will need to create a virtual directory on the server in order to get an http access to the xml file from silverlight). If I choose to do that, I can use LINQ to XML in order to smoothly/gradually consume the xml file (without loading everything at once)
I can simply place my data in a hidden field in the aspx page and then I can access it easily from Silverlight.
Obviously, the second scenario is a lot easier, and also easier to maintain than the first scenario.
The question is: which of the two scenario will I choose? (maybe a third option I'm not aware of?)
Will using the second schenario cause a bottleneck? perhaps on the long term?
If the 160k will only make one trip from the server to the client, then I see no need to use anything more than a hidden field.
If the page were going to be "posted back", so that the 160k would also go back to the server and then maybe back to the client again, then I would use a simple service to get the data from the server to the client, once. That service could be a SOAP service using WCF, or a Web API service. Since you're using Silverlight, it might be convenient to have the service send XML to the client, and the Silverlight code could then easily parse the data using XDocument.
transfer data (string) from the server to Silverlight.
One way would be to use SignalR to transfer the data from the server to a Silverlight client. The setup IMHO is less intense and the communication channel could be used for a continuous line of communication as needed.
Since no programs exist in a vacuum...isn't there a shared database? If so have the page send its information to the database instead, to be read by the Silverlight app.
is there any easy way to show images in asp.net page from a ftp server?
If your password is secure then follow below steps :-
You really should create an FTP account that only has access to the folder with the images on your FTP server. Do that as soon as possible.
For a better overall solution, either synchronize the images to your webserver, or write an HTTP handler that will fetch the image server-side and streams the bytes to the client as if the image was on your server. Have a look at System.Net.FtpWebRequest for the second solution.
If you have write access to disk on the web server, you could implement both parts of the solution. So if an image is fetched the first time, write it to disk before sending it to the client. The next time it's requested, simply redirect the request to the image on disk (or dynamically change the URL of the tag for that product). This way, you build a cache of the images on your web server as time passes. Of course, you need to be able to invalidate the cache in case an image is updated.
<img src="ftp://..."/>