GTLRUploadParameters.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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/wiki#uploading-files
  17. #import <Foundation/Foundation.h>
  18. #import "GTLRDefines.h"
  19. NS_ASSUME_NONNULL_BEGIN
  20. /**
  21. * Upload parameters are required for chunked-resumable or simple/multipart uploads.
  22. *
  23. * The MIME type and one source for data (@c NSData, file URL, or @c NSFileHandle) must
  24. * be specified.
  25. */
  26. @interface GTLRUploadParameters : NSObject <NSCopying>
  27. /**
  28. * The type of media being uploaded.
  29. */
  30. @property(atomic, copy, nullable) NSString *MIMEType;
  31. /**
  32. * The media to be uploaded, represented as @c NSData.
  33. */
  34. @property(atomic, retain, nullable) NSData *data;
  35. /**
  36. * The URL for the local file to be uploaded.
  37. */
  38. @property(atomic, retain, nullable) NSURL *fileURL;
  39. /**
  40. * The media to be uploaded, represented as @c NSFileHandle.
  41. *
  42. * @note This property is provided for compatibility with older code.
  43. * Uploading using @c fileURL is preferred over @c fileHandle
  44. */
  45. @property(atomic, retain, nullable) NSFileHandle *fileHandle;
  46. /**
  47. * Resuming an in-progress resumable, chunked upload is done with the upload location URL,
  48. * and requires a file URL or file handle for uploading.
  49. */
  50. @property(atomic, retain, nullable) NSURL *uploadLocationURL;
  51. /**
  52. * Small uploads (for example, under 200K) can be done with a single multipart upload
  53. * request. The upload body must be provided as NSData, not a file URL or file handle.
  54. *
  55. * Default value is NO.
  56. */
  57. @property(atomic, assign) BOOL shouldUploadWithSingleRequest;
  58. /**
  59. * Uploads may be done without a JSON body as metadata in the initial request.
  60. *
  61. * Default value is NO.
  62. */
  63. @property(atomic, assign) BOOL shouldSendUploadOnly;
  64. /**
  65. * Uploads may use a background session when uploading via GTMSessionUploadFetcher.
  66. * Since background session fetches are slower than foreground fetches, this defaults
  67. * to NO.
  68. *
  69. * It's reasonable for an application to set this to YES for a rare upload of a large file.
  70. *
  71. * Default value is NO.
  72. *
  73. * For more information about the hazards of background sessions, see the header comments for
  74. * the GTMSessionFetcher useBackgroundSession property.
  75. */
  76. @property(atomic, assign) BOOL useBackgroundSession;
  77. /**
  78. * Constructor for uploading from @c NSData.
  79. *
  80. * @param data The data to uploaded.
  81. * @param mimeType The media's type.
  82. *
  83. * @return The upload parameters object.
  84. */
  85. + (instancetype)uploadParametersWithData:(NSData *)data
  86. MIMEType:(NSString *)mimeType;
  87. /**
  88. * Constructor for uploading from a file URL.
  89. *
  90. * @param fileURL The file to upload.
  91. * @param mimeType The media's type.
  92. *
  93. * @return The upload parameters object.
  94. */
  95. + (instancetype)uploadParametersWithFileURL:(NSURL *)fileURL
  96. MIMEType:(NSString *)mimeType;
  97. /**
  98. * Constructor for uploading from a file handle.
  99. *
  100. * @note This method is provided for compatibility with older code. To upload files,
  101. * use a file URL.
  102. */
  103. + (instancetype)uploadParametersWithFileHandle:(NSFileHandle *)fileHandle
  104. MIMEType:(NSString *)mimeType;
  105. @end
  106. NS_ASSUME_NONNULL_END