GTLRUploadParameters.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* Copyright (c) 2011 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. // Uploading documentation:
  16. // https://github.com/google/google-api-objectivec-client-for-rest/blob/main/USING.md#uploading-files
  17. #import <Foundation/Foundation.h>
  18. NS_ASSUME_NONNULL_BEGIN
  19. /**
  20. * Upload parameters are required for chunked-resumable or simple/multipart uploads.
  21. *
  22. * The MIME type and one source for data (@c NSData, file URL, or @c NSFileHandle) must
  23. * be specified.
  24. */
  25. @interface GTLRUploadParameters : NSObject <NSCopying>
  26. /**
  27. * The type of media being uploaded.
  28. */
  29. @property(atomic, copy, nullable) NSString *MIMEType;
  30. /**
  31. * The media to be uploaded, represented as @c NSData.
  32. */
  33. @property(atomic, retain, nullable) NSData *data;
  34. /**
  35. * The URL for the local file to be uploaded.
  36. */
  37. @property(atomic, retain, nullable) NSURL *fileURL;
  38. /**
  39. * The media to be uploaded, represented as @c NSFileHandle.
  40. *
  41. * @note This property is provided for compatibility with older code.
  42. * Uploading using @c fileURL is preferred over @c fileHandle
  43. */
  44. @property(atomic, retain, nullable) NSFileHandle *fileHandle;
  45. /**
  46. * Resuming an in-progress resumable, chunked upload is done with the upload location URL,
  47. * and requires a file URL or file handle for uploading.
  48. */
  49. @property(atomic, retain, nullable) NSURL *uploadLocationURL;
  50. /**
  51. * Small uploads (for example, under 200K) can be done with a single multipart upload
  52. * request. The upload body must be provided as NSData, not a file URL or file handle.
  53. *
  54. * Default value is NO.
  55. */
  56. @property(atomic, assign) BOOL shouldUploadWithSingleRequest;
  57. /**
  58. * Uploads may be done without a JSON body as metadata in the initial request.
  59. *
  60. * Default value is NO.
  61. */
  62. @property(atomic, assign) BOOL shouldSendUploadOnly;
  63. /**
  64. * Uploads may use a background session when uploading via GTMSessionUploadFetcher.
  65. * Since background session fetches are slower than foreground fetches, this defaults
  66. * to NO.
  67. *
  68. * It's reasonable for an application to set this to YES for a rare upload of a large file.
  69. *
  70. * Default value is NO.
  71. *
  72. * For more information about the hazards of background sessions, see the header comments for
  73. * the GTMSessionFetcher useBackgroundSession property.
  74. */
  75. @property(atomic, assign) BOOL useBackgroundSession;
  76. /**
  77. * Constructor for uploading from @c NSData.
  78. *
  79. * @param data The data to uploaded.
  80. * @param mimeType The media's type.
  81. *
  82. * @return The upload parameters object.
  83. */
  84. + (instancetype)uploadParametersWithData:(NSData *)data
  85. MIMEType:(NSString *)mimeType;
  86. /**
  87. * Constructor for uploading from a file URL.
  88. *
  89. * @param fileURL The file to upload.
  90. * @param mimeType The media's type.
  91. *
  92. * @return The upload parameters object.
  93. */
  94. + (instancetype)uploadParametersWithFileURL:(NSURL *)fileURL
  95. MIMEType:(NSString *)mimeType;
  96. /**
  97. * Constructor for uploading from a file handle.
  98. *
  99. * @note This method is provided for compatibility with older code. To upload files,
  100. * use a file URL.
  101. */
  102. + (instancetype)uploadParametersWithFileHandle:(NSFileHandle *)fileHandle
  103. MIMEType:(NSString *)mimeType;
  104. @end
  105. NS_ASSUME_NONNULL_END