简体   繁体   English

如何在另一台服务器上保存文件(pdf/excel)?

[英]How to save files (pdf/excel) in another server?

I have a web API hosted on server 101.111.111.111 .我有一个 web API 托管在服务器101.111.111.111上。 It accepts files in form data.它接受表单数据中的文件。 My question is how to save this files in another server(Ex: 101.111.111.112 )?.我的问题是如何将此文件保存在另一台服务器中(例如: 101.111.111.112 )? I didn't find much examples for this in web.我在 web 中没有找到太多这方面的例子。

I have this code to save in my local folder:我将此代码保存在我的本地文件夹中:

var file = Request.Form.Files[i];
                                var folderName = Path.Combine("D:\\Loans", fileInfo.LoanID, fileInfo.Alias );
                                var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName);
                                if (!Directory.Exists(pathToSave))
                                {
                                    Directory.CreateDirectory(pathToSave);
                                }
                           var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                           var fullPath = Path.Combine(pathToSave, fileName);
                           var dbPath = Path.Combine(folderName, fileName);
                           using (var stream = new FileStream(fullPath, FileMode.Create))
                           {
                                file.CopyTo(stream);
                           }

One way is that create a share folder on server 101.111.111.112 and then map that shared folder with map.network drive...(In Windows) on server 101.111.111.111 and then use that folder like local folder in your code.一种方法是在服务器 101.111.111.112 上创建一个共享文件夹,然后在服务器 101.111.111.111 上创建与 map.network 驱动器共享的文件夹...(在 Windows 中)map,然后在代码中像使用本地文件夹一样使用该文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM