File tree Expand file tree Collapse file tree 3 files changed +7
-5
lines changed
Expand file tree Collapse file tree 3 files changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -65,9 +65,9 @@ extension MultipartRequest {
6565 body. appendString ( " \r \n " )
6666
6767 // attachments
68- for attachment in report. attachmentPaths. compactMap ( Attachment . init ( filePath: ) ) {
68+ for attachment in Set ( report. attachmentPaths) . compactMap ( Attachment . init ( filePath: ) ) {
6969 body. appendString ( boundaryPrefix)
70- body. appendString ( " Content-Disposition: form-data; name= \" \( attachment. name ) \" ; filename= \" \( attachment. name ) \" \r \n " )
70+ body. appendString ( " Content-Disposition: form-data; name= \" \( attachment. filename ) \" ; filename= \" \( attachment. filename ) \" \r \n " )
7171 body. appendString ( " Content-Type: \( attachment. mimeType) \r \n \r \n " )
7272 body. append ( attachment. data)
7373 body. appendString ( " \r \n " )
Original file line number Diff line number Diff line change @@ -7,7 +7,9 @@ import CoreServices
77
88struct Attachment {
99 let data : Data
10- let name : String
10+ // file name with extension that represents real file name
11+ let filename : String
12+
1113 let mimeType : String
1214
1315 // Make sure attachments are not bigger than 10 MB.
@@ -32,7 +34,7 @@ struct Attachment {
3234 }
3335
3436 mimeType = Attachment . mimeTypeForPath ( fileUrl: fileURL)
35- name = " attachment_ " + ( fileURL. lastPathComponent as NSString ) . deletingPathExtension + " _ \( arc4random ( ) ) "
37+ filename = " attachment_ " + fileURL. lastPathComponent
3638 }
3739
3840 static private func mimeTypeForPath( fileUrl: URL ) -> String {
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ final class AttachmentTests: QuickSpec {
3333 it ( " has mime type: text/plain " ) {
3434 expect ( attachment. mimeType) . to ( equal ( " text/plain " ) )
3535 expect ( attachment. data) . toNot ( beNil ( ) )
36- expect ( attachment. name ) . to ( contain ( [ " attachment_test_ " ] ) )
36+ expect ( attachment. filename ) . to ( contain ( [ " attachment_test " ] ) )
3737 }
3838 } else {
3939 fail ( )
You can’t perform that action at this time.
0 commit comments