GCDWebUploader.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. Copyright (c) 2012-2015, Pierre-Olivier Latour
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * The name of Pierre-Olivier Latour may not be used to endorse
  12. or promote products derived from this software without specific
  13. prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
  18. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #import "GCDWebServer.h"
  26. @class GCDWebUploader;
  27. /**
  28. * Delegate methods for GCDWebUploader.
  29. *
  30. * @warning These methods are always called on the main thread in a serialized way.
  31. */
  32. @protocol GCDWebUploaderDelegate <GCDWebServerDelegate>
  33. @optional
  34. /**
  35. * This method is called whenever a file has been downloaded.
  36. */
  37. - (void)webUploader:(GCDWebUploader*)uploader didDownloadFileAtPath:(NSString*)path;
  38. /**
  39. * This method is called whenever a file has been uploaded.
  40. */
  41. - (void)webUploader:(GCDWebUploader*)uploader didUploadFileAtPath:(NSString*)path;
  42. /**
  43. * This method is called whenever a file or directory has been moved.
  44. */
  45. - (void)webUploader:(GCDWebUploader*)uploader didMoveItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath;
  46. /**
  47. * This method is called whenever a file or directory has been deleted.
  48. */
  49. - (void)webUploader:(GCDWebUploader*)uploader didDeleteItemAtPath:(NSString*)path;
  50. /**
  51. * This method is called whenever a directory has been created.
  52. */
  53. - (void)webUploader:(GCDWebUploader*)uploader didCreateDirectoryAtPath:(NSString*)path;
  54. @end
  55. /**
  56. * The GCDWebUploader subclass of GCDWebServer implements an HTML 5 web browser
  57. * interface for uploading or downloading files, and moving or deleting files
  58. * or directories.
  59. *
  60. * See the README.md file for more information about the features of GCDWebUploader.
  61. *
  62. * @warning For GCDWebUploader to work, "GCDWebUploader.bundle" must be added
  63. * to the resources of the Xcode target.
  64. */
  65. @interface GCDWebUploader : GCDWebServer
  66. /**
  67. * Returns the upload directory as specified when the uploader was initialized.
  68. */
  69. @property(nonatomic, readonly) NSString* uploadDirectory;
  70. /**
  71. * Sets the delegate for the uploader.
  72. */
  73. @property(nonatomic, assign) id<GCDWebUploaderDelegate> delegate;
  74. /**
  75. * Sets which files are allowed to be operated on depending on their extension.
  76. *
  77. * The default value is nil i.e. all file extensions are allowed.
  78. */
  79. @property(nonatomic, copy) NSArray* allowedFileExtensions;
  80. /**
  81. * Sets if files and directories whose name start with a period are allowed to
  82. * be operated on.
  83. *
  84. * The default value is NO.
  85. */
  86. @property(nonatomic) BOOL allowHiddenItems;
  87. /**
  88. * Sets the title for the uploader web interface.
  89. *
  90. * The default value is the application name.
  91. *
  92. * @warning Any reserved HTML characters in the string value for this property
  93. * must have been replaced by character entities e.g. "&" becomes "&amp;".
  94. */
  95. @property(nonatomic, copy) NSString* title;
  96. /**
  97. * Sets the header for the uploader web interface.
  98. *
  99. * The default value is the same as the title property.
  100. *
  101. * @warning Any reserved HTML characters in the string value for this property
  102. * must have been replaced by character entities e.g. "&" becomes "&amp;".
  103. */
  104. @property(nonatomic, copy) NSString* header;
  105. /**
  106. * Sets the prologue for the uploader web interface.
  107. *
  108. * The default value is a short help text.
  109. *
  110. * @warning The string value for this property must be raw HTML
  111. * e.g. "<p>Some text</p>"
  112. */
  113. @property(nonatomic, copy) NSString* prologue;
  114. /**
  115. * Sets the epilogue for the uploader web interface.
  116. *
  117. * The default value is nil i.e. no epilogue.
  118. *
  119. * @warning The string value for this property must be raw HTML
  120. * e.g. "<p>Some text</p>"
  121. */
  122. @property(nonatomic, copy) NSString* epilogue;
  123. /**
  124. * Sets the footer for the uploader web interface.
  125. *
  126. * The default value is the application name and version.
  127. *
  128. * @warning Any reserved HTML characters in the string value for this property
  129. * must have been replaced by character entities e.g. "&" becomes "&amp;".
  130. */
  131. @property(nonatomic, copy) NSString* footer;
  132. /**
  133. * This method is the designated initializer for the class.
  134. */
  135. - (instancetype)initWithUploadDirectory:(NSString*)path;
  136. @end
  137. /**
  138. * Hooks to customize the behavior of GCDWebUploader.
  139. *
  140. * @warning These methods can be called on any GCD thread.
  141. */
  142. @interface GCDWebUploader (Subclassing)
  143. /**
  144. * This method is called to check if a file upload is allowed to complete.
  145. * The uploaded file is available for inspection at "tempPath".
  146. *
  147. * The default implementation returns YES.
  148. */
  149. - (BOOL)shouldUploadFileAtPath:(NSString*)path withTemporaryFile:(NSString*)tempPath;
  150. /**
  151. * This method is called to check if a file or directory is allowed to be moved.
  152. *
  153. * The default implementation returns YES.
  154. */
  155. - (BOOL)shouldMoveItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath;
  156. /**
  157. * This method is called to check if a file or directory is allowed to be deleted.
  158. *
  159. * The default implementation returns YES.
  160. */
  161. - (BOOL)shouldDeleteItemAtPath:(NSString*)path;
  162. /**
  163. * This method is called to check if a directory is allowed to be created.
  164. *
  165. * The default implementation returns YES.
  166. */
  167. - (BOOL)shouldCreateDirectoryAtPath:(NSString*)path;
  168. @end