GraphQLFile


STRUCT

GraphQLFile

Swift
1public struct GraphQLFile: Hashable

A file which can be uploaded to a GraphQL server

Properties

fieldName

Swift
1public let fieldName: String

originalName

Swift
1public let originalName: String

mimeType

Swift
1public let mimeType: String

data

Swift
1public let data: Data?

fileURL

Swift
1public let fileURL: URL?

contentLength

Swift
1public let contentLength: UInt64

octetStreamMimeType

Swift
1public static let octetStreamMimeType = "application/octet-stream"

A convenience constant for declaring your mimetype is octet-stream.

Methods

init(fieldName:originalName:mimeType:data:)

Swift
1public init(fieldName: String,
2            originalName: String,
3            mimeType: String = GraphQLFile.octetStreamMimeType,
4            data: Data)

Convenience initializer for raw data

  • Parameters:

    • fieldName: The name of the field this file is being sent for

    • originalName: The original name of the file

    • mimeType: The mime type of the file to send to the server. Defaults to GraphQLFile.octetStreamMimeType.

    • data: The raw data to send for the file.

Parameters

NameDescription
fieldNameThe name of the field this file is being sent for
originalNameThe original name of the file
mimeTypeThe mime type of the file to send to the server. Defaults to GraphQLFile.octetStreamMimeType.
dataThe raw data to send for the file.

init(fieldName:originalName:mimeType:fileURL:)

Swift
1public init(fieldName: String,
2             originalName: String,
3             mimeType: String = GraphQLFile.octetStreamMimeType,
4             fileURL: URL) throws

Throwing convenience initializer for files in the filesystem

  • Parameters:

    • fieldName: The name of the field this file is being sent for

    • originalName: The original name of the file

    • mimeType: The mime type of the file to send to the server. Defaults to GraphQLFile.octetStreamMimeType.

    • fileURL: The URL of the file to upload.

  • Throws: If the file's size could not be determined

Parameters

NameDescription
fieldNameThe name of the field this file is being sent for
originalNameThe original name of the file
mimeTypeThe mime type of the file to send to the server. Defaults to GraphQLFile.octetStreamMimeType.
fileURLThe URL of the file to upload.

generateInputStream()

Swift
1public func generateInputStream() throws -> InputStream

Uses either the data or the file URL to create an InputStream that can be used to stream data into a multipart-form.

  • Returns: The created InputStream.

  • Throws: If an input stream could not be created from either data or a file URL.

Feedback

Edit on GitHub

Forums