我使用的是.NET库函数上传文件到服务器,并作为一个参数一个文件路径。我要发送的数据小,在运行时构建的。我可以将它保存到临时文件,然后上传。
I am using a .NET library function that uploads files to a server, and takes as a parameter a path to a file. The data I want to send is small and constructed at runtime. I can save it to a temporary file and then upload it.
由于我的应用程序将被部署在各种环境中,我不知道如果我将能够可靠地创建临时文件,这将是preferable能在一个路径传递到虚拟文件在存储器
Since my application will be deployed in a variety of environments, and I don't know if I'll be able to create the temporary file reliably, it would be preferable to be able to pass in a path to a virtual file in memory.
我不能改变图书馆;我知道它在执行该文件的以下内容:
I can't change the library; I know it executes the following on the file:
LibraryUploadFunction(string filename) { fileName = Path.GetFullPath(fileName); FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); ... }
是否有可能避免写入到磁盘文件?
Is it possible to avoid writing the file to disk?
感谢
编辑:
库调用Webclient.UploadFile,如回答指出,有许多可能的解决方法,其中包括使用替代库,其中有很多。
The library call is Webclient.UploadFile, as pointed out in the answers, there are many workarounds possible, including using alternative libraries, of which there are many.
推荐答案没有,您的图书馆在这方面根本不灵活,通过它使用的事实的FileStream 。
No, your library is fundamentally inflexible in this aspect, by the fact that it uses FileStream.
选项:
- 使用一个RAMDRIVE并在指定的路径,以避免实际命中磁盘
- 在不同的地方图书馆的来源,或者要求的变化(如果它是封闭源代码),或仅仅的做的,如果它是开源的变化
- 使用不同的库。 (有什么特别之处吗?)
- Use a ramdrive and specify a path on that, in order to avoid actually hitting disk
- Depending on where the library comes from, either request a change (if it's closed source) or just make the change if it's open source
- Use a different library. (What's special about this one?)
更多推荐
在内存中创建的文件不是文件系统
发布评论