You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 13
Next »
Creates a file in the BFS, based on the input in in the FileInfoUpload
Name | Type | Description | Mandatory | Available from version |
---|
FileInfoUpload | FileInfoUpload | An instance of the FileInfoUpload class | | |
Response rows
| | | Available from version |
---|
Message | String | The outcome of the operation ("OK" if everything was correct) | |
Code examples
var client = new BFSServiceReference.bfsapiSoapClient(); var credentials = new BFSServiceReference.Credentials() { UserName = bfsusername, //Username of administrative user in your instance of BFS Password = bfspassword, //Password of the administrative user in your instance of BFS };
// Get information about the file to upload to BFS
FileInfo fInfo = new FileInfo(@"c:\temp\test.txt");
// in real life make sure the length don't exceed the maximum setting (default is 4 MB limit)
long numBytes = fInfo.Length;
double dLen = Convert.ToDouble(fInfo.Length / 1000000);
FileStream fStream = new FileStream(@"c:\temp\test_new.txt",
FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fStream);
// convert the file to a byte array
byte[] data = br.ReadBytes((int)numBytes);
br.Close();
CreateFileRequest oReq = new CreateFileRequest();
oReq.Credentials = credentials;
oReq.identify = bfsidentifier; //Identifier is a unique token for your instance of BFS
oReq.FileInfoUpload = new FileInfoUpload
{
ContentType = "text", // choose appropiate content type based on your file
fileBytes = data,
FileName = "test_new.txt", // the name of file as you would like to name it in BFS
Owner = new Guid("xxxxx-xxx-xxxx-xxxx-xxxxxxxxxxxx"), // The owner of the file, see GetPersons for reference
Permission = FilePermission.All // Type of permission that should apply to this file (AdminOnly/AdminPartner/All)
};
CreateFileResponse Rep = client.CreateFile(oReq);
if (oRep.Message == "OK")
{
Console.Writeline("Upload successful");
}
else
{
Console.Writeline(string.format("Upload not successful: {0}", Rep.Message));
}