Update in attachment proccess#321
Conversation
| /// <param name="filePath">The path of the file to attach.</param> | ||
| /// <param name="ct">(Optional) A cancellation token for async processing.</param> | ||
| /// <returns>The newly created <see cref="IBoardBackground"/>.</returns> | ||
| Task<IBoardBackground> Add(string filePath, CancellationToken ct = default); |
There was a problem hiding this comment.
Instead of changing this, can you just add the new method, please? This will allow us to avoid a breaking change.
There was a problem hiding this comment.
Alright, its seems to be a great idea
| /// The file path | ||
| /// </summary> | ||
| public byte[] ContentBytes { get; set; } | ||
| public string FilePath { get; set; } |
There was a problem hiding this comment.
Similarly here: just add the property.
| TrelloConfiguration.Log.Debug($"\tContent: {formData}"); | ||
|
|
||
| return formData; | ||
| var fileStream = File.Open(request.File, FileMode.Open); |
There was a problem hiding this comment.
Here you will need to check whether raw bytes have been uploaded or just a filename; then act appropriately.
gregsdennis
left a comment
There was a problem hiding this comment.
I think I'll move forward with this, but I don't want to lose existing functionality. Just a few suggestions on how to add this without creating breaking changes.
| var fileStream = File.Open(request.File, FileMode.Open); | ||
| var fileInfo = new FileInfo(request.File); | ||
| formData.Add(new StreamContent(fileStream), "\"file\"", string.Format("\"{0}\"", "as" + fileInfo.Extension)); | ||
| formData.Add(new StringContent("mimeType"), "image/png"); |
There was a problem hiding this comment.
I'd like to have some simple functionality that attempts to infer the mime type from the file extension. Not looking for an extensive list; more like a "top 10."
gregsdennis
left a comment
There was a problem hiding this comment.
Some comments. Also tabs, not spaces, please.
| var sourceCard = await TestEnvironment.Current.BuildCard(); | ||
| var jpeg = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Files/smallest-jpeg.jpg"); | ||
| await sourceCard.Attachments.Add(File.ReadAllBytes(jpeg), "smallest-jpeg.jpg"); | ||
| var pdf = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Files/smallest-jpeg.jpg"); |
There was a problem hiding this comment.
I'd prefer not to change the client tests since they're associated with specific issues. Can you create a new test that uses the new code path, please?
| /// <param name="name">A name for the sticker.</param> | ||
| /// <param name="ct">(Optional) A cancellation token for async processing.</param> | ||
| /// <returns>The <see cref="ISticker"/> generated by Trello.</returns> | ||
| Task<ISticker> Add(string filePath, string name, CancellationToken ct = default); |
There was a problem hiding this comment.
Please add an override.
| { | ||
| var rf = (RestFile)parameter.Value; | ||
| request.AddFile(parameter.Key, rf.ContentBytes, rf.FileName); | ||
| request.AddFile(parameter.Key, rf.FilePath, rf.FileName); |
There was a problem hiding this comment.
We need to check which attachment method we're using here. I don't want to completely replace the existing bytes method.
| var fileStream = File.Open(request.FilePath, FileMode.Open); | ||
| var fileInfo = new FileInfo(request.FilePath); | ||
| formData.Add(new StreamContent(fileStream), "\"file\"", string.Format("\"{0}\"", "as" + fileInfo.Extension)); | ||
| formData.Add(new StringContent("mimeType"), "image/png"); |
There was a problem hiding this comment.
I'd still like to have some basic mime type checking rather than always assuming png.
| if (request.FilePath != null) | ||
| { |
There was a problem hiding this comment.
Here I am verifying, whether the file is uploaded or byte array.
|
|
||
| if (rf.FilePath != null) | ||
| { |
| public void AddFile(string key, string filePath, string fileName) | ||
| { | ||
| FilePath = filePath; | ||
| FileName = fileName; | ||
| } |
There was a problem hiding this comment.
Here, overloading the of AddFile method for assigning file location as well
|
I don't know what your editor is doing, but it keeps putting spaces in instead of tabs. The alignment is all off. Also, for the build, the card attachment test is failing. I'd like to also see a test that uses your method to attach a file. The |
|
Hi Greg,
#318 (comment) is working fine and is uploading all types of file correctly. However, the problem occurs when your tired to download the uploaded files (from trello board) specifically pdf, excel and document files etc. In addition when ones tries to view .pdf, .docx files will not be able to view it on trello board.
However, if the WebApiClient file method GetContent is modified like this
This code is still be able to upload all types of files, and the user will also be able to download file in original format, and can view it on the trello board as well.