.NET Webservice:保存图片的位置 [英] .NET Webservice: where to save pictures

查看:83
本文介绍了.NET Webservice:保存图片的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在开发一个VB.NET网络服务。它的目的是保存员工身份证件(姓名,员工编号,照片)的数据,以便以后不同的客户端应用程序可以访问这些数据。



名称例如保存到SQL DB中。但是在哪里保存照片?它被作为Byte Array提供给webservice并且必须保存在某个地方。



web服务应该将Photo保存到一个文件夹中,这样每个客户端应用程序都可以通过以下方式访问照片:调用公共网址例如

https://192.168.1.1/MyWebservice/Photos/Employee1234.jpg (作为网络服务的子文件夹)

或类似

https://192.168.1.1/EmployeePhotos/Employee1234.jpg (作为单独的URL)



理想情况下,Picturefile应该可以在共享文件夹中访问,

以防客户端应用程序(例如工资和销售软件)不支持URL,但仅支持目录路径 \\192.168.1.1\Photos\Employee1234.jpg



我是不确定什么是最佳实践:

- 将图片保存到webservice的子文件夹中(冒犯后果,在部署新版本的t期间可能会错误地删除子文件夹内容)他的网络服务)?如何访问Directoryname(任何命令,如Server.MapPath?)

- .NET是否为像我这样的问题提供特殊文件夹?

- 将图片保存到外面的目录中webservice文件夹? (这是可能的还是在服务器上沙箱化的webservices?)。另外还有一个共享文件夹,用于通过URL和Folderpath访问文件?



我将非常感谢你的想法和提示

你的

Phil

Hi everyone,

I'm developing a VB.NET webservice. It's purpose is to save data of employee identification badges (Name, Employee Number, Photo), so that the data can be accessed by different client applications later.

Name e.g. is saved into an SQL DB. But where to save the photo? It is given to the webservice as Byte Array and must be saved somewhere.

The webservice should save the Photo into a folder, so every client application can access the photo by calling a public URL e.g.
https://192.168.1.1/MyWebservice/Photos/Employee1234.jpg (as a subfolder of the webservice)
or like
https://192.168.1.1/EmployeePhotos/Employee1234.jpg (as separate URL)

Ideally the Picturefiles should be accessible in a shared folder, too,
in case a client application (e.g. the wage and salery software) does not support URLs but directory paths \\192.168.1.1\Photos\Employee1234.jpg only.

I'm uncertain what's the best practice:
- save the picture into a subfolder of the webservice (hazarding the consequences, that the subfolders content could be deleted by mistake during the deployment of a new release of the webservice)? How to access the Directoryname (any command like Server.MapPath?)
- does .NET provide special folders for problems like mine?
- save the picture into a directory outside the webservice folder? (Is this possible or are webservices sandboxed on the server?). And additionally a share on this folder to access the files by URL and Folderpath?

I would be grateful for your ideas and hints
Yours
Phil

推荐答案

您可以创建多个子目录来在应用程序中保存不同类型的图像。父目录可以是这样的, https://192.168.1.1/Images ,然后在其中,您可以为EmployeePhotos,ApplicationImages(例如徽标,社交按钮等)创建不同的文件夹。不要创建文件夹MyWebService;客户知道IP地址以您自己的服务为目标。



如果要在绝对路径中解决,可以使用Server.MapPath()函数。 MapPath返回绝对路径。由于您不希望自己弄脏手,或者允许其他人使用该目录的绝对路径,因此您可以忽略它。 :)



在.NET中,您可以枚举多个目录,并在您喜欢的机器上使用哪个目录。从.NET中的机器获取目录的代码是这样的,



You could possibly make multiple sub-directories to hold different sort of images in your applications. The parent directory could be something like this, https://192.168.1.1/Images, then inside it you can create different folders for EmployeePhotos, ApplicationImages (such as the logo, social buttons etc). Do not create the folder MyWebService; clients know that the IP address targets your own service.

You can possibly use the Server.MapPath() function, if you're going to work around in the absolute paths. MapPath returns the absolute paths. Since you do not want yourself getting hands dirty, or to allow anyone else to use that absolute path to the directory, you can ignore it. :)

In .NET, you can possibly enumerate over multiple directories, and use which so ever directory over the machine that you like. A code to get directories from machine in .NET is like this,

// Absolute path to the AppData folder; you can create your folder there
Environment.GetSpecialFolder(Environment.SpecialFolder.ApplicationData);





你可以阅读此MSDN文档 [ ^ ],了解有关此过程的更多信息。



这不是一个好主意,您可以将图像存储在本地Images文件夹中,表示在您的Web服务中,此文件夹仅用于图像数据。



You can read this MSDN document[^], to learn more on this process.

That won't be a good idea, you can store the images right inside a local "Images" folder, that would indicate that inside your web service this folder is meant for the image data only.


这篇关于.NET Webservice:保存图片的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆