Skip to content

Commit

Permalink
#245 Improvement for option for multiple values for the same field na…
Browse files Browse the repository at this point in the history
…me in an Upload task

To specify multiple values for a single name, format the value as '"value1", "value2", "value3"'.
Specifically, the value needs to match the following RegEx: ^(?:"[^"]+"\s*,\s*)+"[^"]+"$
  • Loading branch information
781flyingdutchman committed Feb 20, 2024
1 parent a4c56bc commit b3a4021
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class UploadTaskWorker(applicationContext: Context, workerParams: WorkerParamete
): TaskStatus {
// field portion of the multipart, all in one string
// multiple values should be encoded as '"value1", "value2", ...'
val multiValueRegEx = Regex("""(?:"[^"]+"\s*,\s*)*"[^"]+"""")
val multiValueRegEx = Regex("""^(?:"[^"]+"\s*,\s*)+"[^"]+"$""")
var fieldsString = ""
for (entry in task.fields.entries) {
// Check if the entry value matches the multiple values format
Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/Uploader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class Uploader : NSObject, URLSessionTaskDelegate, StreamDelegate {
}
// field portion of the multipart, all in one string
// multiple values should be encoded as '"value1", "value2", ...'
let multiValueRegEx = try! NSRegularExpression(pattern: #"(?:"[^"]+"\s*,\s*)*"[^"]+""#, options: [])
let multiValueRegEx = try! NSRegularExpression(pattern: #"^(?:"[^"]+"\s*,\s*)+"[^"]+"$"#, options: [])
for entry in task.fields ?? [:] {
let value = entry.value
let fullRange = NSRange(location: 0, length: value.utf16.count)
Expand Down
2 changes: 1 addition & 1 deletion lib/src/desktop/upload_isolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Future<TaskStatus> multipartUpload(
UploadTask task, String filePath, SendPort sendPort) async {
// field portion of the multipart, all in one string
// multiple values should be encoded as '"value1", "value2", ...'
final multiValueRegEx = RegExp(r'(?:"[^"]+"\s*,\s*)*"[^"]+"');
final multiValueRegEx = RegExp(r'^(?:"[^"]+"\s*,\s*)+"[^"]+"$');
var fieldsString = '';
for (var entry in task.fields.entries) {
if (multiValueRegEx.hasMatch(entry.value)) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ final class UploadTask extends Task {

/// Map of name/value pairs to encode as form fields in a multi-part upload.
/// To specify multiple values for a single name, format the value as
/// '"value1", "value2", "value3"' (note the double quotes and
/// the comma to separate the values).
/// '"value1", "value2", "value3"' so that it matches the following
/// RegEx: ^(?:"[^"]+"\s*,\s*)+"[^"]+"$
final Map<String, String> fields;

/// Creates [UploadTask]
Expand Down

0 comments on commit b3a4021

Please sign in to comment.