Upload file to Gallery REST SDK

Trying to use the REST SDK to upload a file to a gallery.  Everything looks like it works, but the file seems corrupted when I try download/view it from my community.  I'm not entirely how to pass in the filedata as a byte array as the method asks for a string and not sure I'm encoding it correctly.

byte[] fileData = System.IO.File.ReadAllBytes(myPdfPath);

                    // Add as a new media item to Telligent
                    var response = host.PostToDynamic(2, "media/{mediagalleryid}/files.json", false, new RestPostOptions
                    {
                        PathParameters = new System.Collections.Specialized.NameValueCollection {
                            { "mediagalleryid", "246" }
                        },
                        PostParameters = new System.Collections.Specialized.NameValueCollection {
                            { "Name", resourceFileName },
                            { "FileName", resourceFileName},
                            { "FileData", String.Join(" ", fileData)},
                            { "ContentType", MimeMapping.GetMimeMapping(resourceFileName)},
                            { "Tags", tags},
                            { "Description", description}
                        }
                    });



Updated
[edited by: Luke R Davidson at 11:25 AM (GMT 0) on Fri, Dec 18 2020]
Parents Reply
  •                     using (var fileStream = new FileStream(path.Replace("assets.csv",resourceFileName), FileMode.Open, FileAccess.Read))
                        {
                            fileStream.Position = 0;
                            Guid uploadContextId = Guid.NewGuid();
                            UploadedFile file = new UploadedFile(uploadContextId, resourceFileName, MimeMapping.GetMimeMapping(resourceFileName), fileStream);
    
                            UploadedFileInfo fileInfo = host.UploadFile(file);
    
                            if(!fileInfo.IsError)
                            {
                                var pathParameters = new NameValueCollection();
                                pathParameters.Add("mediagalleryid", "247");
                                dynamic mediaResponse = host.PostToDynamic(2, "media/{mediagalleryid}/files.json", false,
                                    new RestPostOptions()
                                    {
                                        PathParameters = pathParameters,
                                        PostParameters = new System.Collections.Specialized.NameValueCollection {
                                            { "Name", resourceFileName },
                                            { "FileName", resourceFileName.Trim()},
                                            { "FileUploadContext", fileInfo.UploadContext.ToString()},
                                            { "ContentType", MimeMapping.GetMimeMapping(resourceFileName)},
                                            { "Tags", tags},
                                            { "Description", description}
                                        }
                                    });
                            }
                        }

Children