How to use name method of com.github.kittinunf.fuel.core.requests.UploadRequest class

Best Fuel code snippet using com.github.kittinunf.fuel.core.requests.UploadRequest.name

Request.kt

Source:Request.kt Github

copy

Full Screen

...81 */82 override fun toString(): String83 /**84 * Get the current values of the header, after normalisation of the header85 * @param header [String] the header name86 * @return the current values (or empty if none)87 */88 operator fun get(header: String): HeaderValues89 /**90 * Set the values of the header, overriding what's there, after normalisation of the header91 *92 * @param header [String] the header name93 * @param values [Collection<*>] the values to be transformed through #toString94 * @return self95 */96 operator fun set(header: String, values: Collection<*>): Request97 /**98 * Set the value of the header, overriding what's there, after normalisation of the header99 *100 * @param header [String] the header name101 * @param value [Any] the value to be transformed through #toString102 */103 operator fun set(header: String, value: Any): Request104 /**105 * Get the current values106 *107 * @see get(header: String)108 * @return [HeaderValues] the current values109 */110 fun header(header: String): HeaderValues111 /**112 * Replace the headers with the map provided113 *114 * @note In earlier versions the mapOf variant of this function worked differently than the vararg pairs variant,115 * which has been changed to make any call to header(...) always overwrite the values and any call to116 * appendHeader(...) will try to append the value.117 *118 * @see set(header: String, values: Collection<*>)119 * @see set(header: String, value: Any)120 *121 * @param map [Map<String, Any>] map of headers to replace. Value can be a list or single value122 * @return [Request] the modified request123 */124 fun header(map: Map<String, Any>): Request125 /**126 * Replace the headers with the pairs provided127 *128 * @note In earlier versions the mapOf variant of this function worked differently than the vararg pairs variant,129 * which has been changed to make any call to header(...) always overwrite the values and any call to130 * appendHeader(...) will try to append the value.131 *132 * @see set(header: String, values: Collection<*>)133 * @see set(header: String, value: Any)134 *135 * @param pairs [Pair<String, Any>] map of headers to replace. Value can be a list or single value136 * @return [Request] the modified request137 */138 fun header(vararg pairs: Pair<String, Any>): Request139 /**140 * Replace the header with the provided values141 *142 * @see set(header: String, values: Collection<*>)143 *144 * @param header [String] the header to set145 * @param values [List<Any>] the values to set the header to146 * @return [Request] the modified request147 */148 fun header(header: String, values: Collection<*>): Request149 /**150 * Replace the header with the provided value151 *152 * @see set(header: String, values: List<Any>)153 *154 * @param header [String] the header to set155 * @param value [Any] the value to set the header to156 * @return [Request] the modified request157 */158 fun header(header: String, value: Any): Request159 /**160 * Replace the header with the provided values161 *162 * @see set(header: String, values: List<Any>)163 *164 * @param header [String] the header to set165 * @param values [Any] the values to set the header to166 * @return [Request] the modified request167 */168 fun header(header: String, vararg values: Any): Request169 /**170 * Appends the value to the header or sets it if there was none yet171 *172 * @param header [String] the header name to append to173 * @param value [Any] the value to be transformed through #toString174 */175 fun appendHeader(header: String, value: Any): Request176 /**177 * Appends the value to the header or sets it if there was none yet178 *179 * @param header [String] the header name to append to180 * @param values [Any] the value to be transformed through #toString181 */182 fun appendHeader(header: String, vararg values: Any): Request183 /**184 * Append each pair, using the key as header name and value as header content185 *186 * @param pairs [Pair<String, Any>]187 */188 fun appendHeader(vararg pairs: Pair<String, Any>): Request189 /**190 * Execute the [Request] asynchronously, using the [handler], into a [ByteArray]191 *192 * @param handler [ResponseResultHandler] the handler to report the [Request], [Response] and Result of [ByteArray]193 * @return [CancellableRequest] the request in flight194 */195 fun response(handler: ResponseResultHandler<ByteArray>): CancellableRequest196 /**197 * Execute the [Request] asynchronously, using the [handler], into a [ByteArray]198 *...

Full Screen

Full Screen

DefaultRequest.kt

Source:DefaultRequest.kt Github

copy

Full Screen

...41 override lateinit var executionOptions: RequestExecutionOptions42 override val body: Body get() = _body43 /**44 * Get the current values of the header, after normalisation of the header45 * @param header [String] the header name46 * @return the current values (or empty if none)47 */48 override operator fun get(header: String): HeaderValues {49 return headers[header]50 }51 /**52 * Set the values of the header, overriding what's there, after normalisation of the header53 *54 * @param header [String] the header name55 * @param values [Collection<*>] the values to be transformed through #toString56 * @return self57 */58 override operator fun set(header: String, values: Collection<*>): Request {59 headers[header] = values.map { it.toString() }60 return request61 }62 /**63 * Set the value of the header, overriding what's there, after normalisation of the header64 *65 * @param header [String] the header name66 * @param value [Any] the value to be transformed through #toString67 */68 override operator fun set(header: String, value: Any): Request {69 when (value) {70 is Collection<*> -> this[header] = value71 else -> headers[header] = value.toString()72 }73 return request74 }75 /**76 * Get the current values77 *78 * @see get(header: String)79 * @return [HeaderValues] the current values80 */81 override fun header(header: String) = get(header)82 /**83 * Replace the headers with the map provided84 *85 * @note In earlier versions the mapOf variant of this function worked differently than the vararg pairs variant,86 * which has been changed to make any call to header(...) always overwrite the values and any call to87 * appendHeader(...) will try to append the value.88 *89 * @see set(header: String, values: Collection<*>)90 * @see set(header: String, value: Any)91 *92 * @param map [Map<String, Any>] map of headers to replace. Value can be a list or single value93 * @return [Request] the modified request94 */95 override fun header(map: Map<String, Any>): Request {96 headers.putAll(Headers.from(map))97 return request98 }99 /**100 * Replace the headers with the pairs provided101 *102 * @note In earlier versions the mapOf variant of this function worked differently than the vararg pairs variant,103 * which has been changed to make any call to header(...) always overwrite the values and any call to104 * appendHeader(...) will try to append the value.105 *106 * @see set(header: String, values: Collection<*>)107 * @see set(header: String, value: Any)108 *109 * @param pairs [Pair<String, Any>] map of headers to replace. Value can be a list or single value110 * @return [Request] the modified request111 */112 override fun header(vararg pairs: Pair<String, Any>): Request {113 headers.putAll(Headers.from(*pairs))114 return request115 }116 /**117 * Replace the header with the provided values118 *119 * @see set(header: String, values: Collection<*>)120 *121 * @param header [String] the header to set122 * @param values [List<Any>] the values to set the header to123 * @return [Request] the modified request124 */125 override fun header(header: String, values: Collection<*>) = set(header, values)126 /**127 * Replace the header with the provided value128 *129 * @see set(header: String, values: List<Any>)130 *131 * @param header [String] the header to set132 * @param value [Any] the value to set the header to133 * @return [Request] the modified request134 */135 override fun header(header: String, value: Any): Request = set(header, value)136 /**137 * Replace the header with the provided values138 *139 * @see set(header: String, values: List<Any>)140 *141 * @param header [String] the header to set142 * @param values [Any] the values to set the header to143 * @return [Request] the modified request144 */145 override fun header(header: String, vararg values: Any) = set(header, values.toList())146 /**147 * Appends the value to the header or sets it if there was none yet148 *149 * @param header [String] the header name to append to150 * @param value [Any] the value to be transformed through #toString151 */152 override fun appendHeader(header: String, value: Any): Request {153 headers.append(header, value)154 return request155 }156 /**157 * Appends the value to the header or sets it if there was none yet158 *159 * @param header [String] the header name to append to160 * @param values [Any] the value to be transformed through #toString161 */162 override fun appendHeader(header: String, vararg values: Any): Request {163 headers.append(header, values.toList())164 return request165 }166 /**167 * Append each pair, using the key as header name and value as header content168 *169 * @param pairs [Pair<String, Any>]170 */171 override fun appendHeader(vararg pairs: Pair<String, Any>): Request {172 pairs.forEach { pair -> appendHeader(pair.first, pair.second) }173 return request174 }175 /**176 * Sets the body to be read from a generic body source.177 *178 * @note in earlier versions the body callback would be called multiple times in order to maybe get the size. But179 * that would lead to closed streams being unable to be read. If the size is known, set it before anything else.180 *181 * @param openStream [BodySource] a function that yields a stream182 * @param calculateLength [Number?] size in +bytes+ if it is known183 * @param charset [Charset] the charset to write with184 * @param repeatable [Boolean] loads the body into memory upon reading185 *186 * @return [Request] the request187 */188 override fun body(openStream: BodySource, calculateLength: BodyLength?, charset: Charset, repeatable: Boolean): Request {189 _body = DefaultBody190 .from(openStream = openStream, calculateLength = calculateLength, charset = charset)191 .let { body -> if (repeatable) body.asRepeatable() else body }192 return request193 }194 /**195 * Sets the body from a generic stream196 *197 * @note the stream will be read from the position it's at. Make sure you rewind it if you want it to be read from198 * the start.199 *200 * @param stream [InputStream] a stream to read from201 * @param calculateLength [Number?] size in bytes if it is known202 * @param charset [Charset] the charset to write with203 * @param repeatable [Boolean] loads the body into memory upon reading204 *205 * @return [Request] the request206 */207 override fun body(stream: InputStream, calculateLength: BodyLength?, charset: Charset, repeatable: Boolean) =208 body(openStream = { stream }, calculateLength = calculateLength, charset = charset, repeatable = repeatable)209 /**210 * Sets the body from a byte array211 *212 * @param bytes [ByteArray] the bytes to write213 * @param charset [Charset] the charset to write with214 * @return [Request] the request215 */216 override fun body(bytes: ByteArray, charset: Charset) =217 body(stream = ByteArrayInputStream(bytes), calculateLength = { bytes.size.toLong() }, charset = charset, repeatable = true)218 /**219 * Sets the body from a string220 *221 * @param body [String] the string to write222 * @param charset [Charset] the charset to write with223 * @return [Request] the request224 */225 override fun body(body: String, charset: Charset): Request =226 body(bytes = body.toByteArray(charset), charset = charset)227 .let {228 if (header(Headers.CONTENT_TYPE).lastOrNull().isNullOrBlank())229 header(Headers.CONTENT_TYPE, "text/plain; charset=${charset.name()}")230 else it231 }232 /**233 * Sets the body to the contents of a file.234 *235 * @note this does *NOT* make this a multipart upload. For that you can use the upload request. This function can be236 * used if you want to upload the single contents of a text based file as an inline body.237 *238 * @note when charset is not UTF-8, this forces the client to use chunked encoding, because file.length() gives the239 * length of the file in bytes without considering the charset. If the charset is to be considered, the file needs240 * to be read in its entirety which defeats the purpose of using a file.241 *242 * @param file [File] the file to write to the body243 * @param charset [Charset] the charset to write with244 * @return [Request] the request245 */246 override fun body(file: File, charset: Charset): Request = when (charset) {247 Charsets.UTF_8 -> body({ FileInputStream(file) }, { file.length() }, charset)248 else -> body({ FileInputStream(file) }, null, charset)249 }.let {250 if (header(Headers.CONTENT_TYPE).lastOrNull().isNullOrBlank()) {251 val contentType = URLConnection.guessContentTypeFromName(file.name)252 header(Headers.CONTENT_TYPE, "$contentType; charset=${charset.name()}")253 } else {254 it255 }256 }257 /**258 * Sets the body to a defined [Body]259 *260 * @param body [Body] the body to assign261 * @return [Request] the request262 */263 override fun body(body: Body): Request {264 _body = body265 return request266 }...

Full Screen

Full Screen

Zendesk.kt

Source:Zendesk.kt Github

copy

Full Screen

...108 "/articles/attachments.json",109 ZendeskApiBody.AttachmentBody::class110 ) {111 override fun get(basePath: String): UploadRequest = super.get(basePath).upload()112 .add(FileDataPart(name = "file", file = File(filePath)))113 .add(InlineDataPart(name = "inline", content = "true"))114 }115 data class LinkAttachedImage(val articleId: Long, val attachmentIds: List<Long>) :116 ZendeskRequest<ZendeskApiBody.EmptyBody>(117 POST,118 "/articles/$articleId/bulk_attachments.json",119 ZendeskApiBody.EmptyBody::class,120 ZendeskApiBody.AttachmentIdsBody(attachmentIds)121 )122 data class GetArticleTranslations(val articleId: Long, val locale: String) :123 ZendeskRequest<ZendeskApiBody.TranslationsBody>(124 GET,125 "/articles/$articleId/translations.json",126 ZendeskApiBody.TranslationsBody::class127 )128 data class UpdateArticleTranslation(val translation: Translation) :129 ZendeskRequest<ZendeskApiBody.EmptyBody>(130 PUT,131 "/articles/${translation.sourceId}/translations/${translation.locale}.json",132 ZendeskApiBody.EmptyBody::class,133 ZendeskApiBody.TranslationBody(translation)134 )135}136class Zendesk(137 val url: String,138 val user: String,139 val password: String,140 val categoryId: Long,141 val pattern: String? = null142) {143 fun createSectionOrOverwriteIfExist(section: NewSection) =144 (pattern?.let {145 getSectionWithPattern(it, section.parentSectionId)146 } ?: getSection(section.name, section.parentSectionId))147 .flatMap {148 DeleteSection(it.id)149 .run()150 .handleErrorWith {151 when (it) {152 is ResourceDoesNotExist -> Unit.right()153 else -> it.left()154 }155 }156 .also { println("Section for version ${section.name} already exists. Deleting it.") }157 .map { section }158 }159 .handleErrorWith {160 when (it) {161 is ResourceDoesNotExist -> section.right()162 else -> it.left()163 }164 }.flatMap { createSection(it) }165 .map { it.id }166 fun createArticle(article: Article) =167 uploadImages(article)168 .map { attachmentsMapping ->169 attachmentsMapping toT article.replaceImgUrlWithAttachmentUrl(attachmentsMapping)170 }171 .flatmapTupleRight(::postArticle)172 .flatMap { (attachments, articleId) ->173 if (attachments.isNotEmpty())174 linkAttachmentsToArticle(attachments.values, articleId)175 else176 Either.right(article)177 }178 fun publishSection(section: ExistingSection) =179 getArticles(section.id)180 .flatMap { articles ->181 articles.map {182 publishArticle(it)183 }.sequence(Either.applicative()).fix()184 }185 .map { Unit }186 private fun getArticleTranslations(articleId: Long) =187 ZendeskRequest.GetArticleTranslations(articleId, "en-us").run()188 .map {189 it.translations190 }191 private fun getArticles(sectionId: Long) =192 ZendeskRequest.GetArticles(sectionId).run()193 .map {194 it.articles195 }196 private fun updateTranslation(translation: Translation) =197 ZendeskRequest.UpdateArticleTranslation(translation).run()198 private fun publishArticle(article: Article) =199 article.id.rightIfNotNull { HtmlToZendeskError.MissingArticleId }200 .flatMap { getArticleTranslations(it) }201 .flatMap { translations ->202 translations.map { translation ->203 updateTranslation(translation.copy(draft = false))204 }.sequence(Either.applicative()).fix()205 }206 .map { Unit }207 private fun uploadArticleImage(path: String) =208 ZendeskRequest.UploadAttachedImage(path).run()209 .map { it.articleAttachment }210 private fun uploadImages(article: Article) =211 article.getBodyImages()212 .map { it to uploadArticleImage("${article.path.parent}/$it") }213 .map { (imgName, uploadResult) ->214 uploadResult.fold({215 it.left()216 }, {217 (imgName to it).right()218 })219 }220 .sequence(Either.applicative()).fix().map { it.fix().toMap() }221 private fun linkAttachmentsToArticle(attachments: Collection<ArticleAttachment>, articleId: Long) =222 ZendeskRequest.LinkAttachedImage(articleId, attachments.map(ArticleAttachment::id)).run()223 private fun postArticle(article: Article) =224 ZendeskRequest.CreateArticle(article).run()225 .flatMap {226 it.article.id.rightIfNotNull {227 UnexpectedRequestResult("The id of the article that has been created is not set. $it ")228 }229 }230 fun getSection(name: String, parentSectionId: Long? = null) =231 ZendeskRequest.GetSections(categoryId).run()232 .flatMap {233 it.sections.firstOrNone { it.name == name && it.parentSectionId == parentSectionId }234 .toEither { ResourceDoesNotExist }235 }236 private fun getSectionWithPattern(pattern: String, parentSectionId: Long? = null) =237 ZendeskRequest.GetSections(categoryId).run()238 .flatMap {239 it.sections.firstOrNone { section ->240 pattern.toRegex().containsMatchIn(section.name) && section.parentSectionId == parentSectionId241 }.toEither { ResourceDoesNotExist }242 }243 private fun createSection(section: NewSection) =244 ZendeskRequest.CreateSection(categoryId, section)245 .run()246 .map { it.section }247 class ZendeskResponseDeserializable2<T : ZendeskApiBody>(val responseType: KClass<out T>) :248 ResponseDeserializable<T> {249 override fun deserialize(content: String): T = when (responseType) {250 ZendeskApiBody.EmptyBody::class -> ZendeskApiBody.EmptyBody as T251 else -> gson.fromJson(content, responseType.java)252 }253 }254 private fun <T : ZendeskApiBody> ZendeskRequest<T>.run(requestConfigBlock: Request.() -> Unit = {}) =...

Full Screen

Full Screen

UploadBody.kt

Source:UploadBody.kt Github

copy

Full Screen

...94 inputAvailable = false95 val lazyDataparts = request.dataParts96 return outputStream.buffered().let { stream ->97 // Parameters98 val parameterLength = request.parameters.sumByDouble { (name, data) ->99 writeParameter(stream, name, data).toDouble()100 }101 // Blobs / Files102 val filesWithHeadersLength = lazyDataparts.sumByDouble { lazyDataPart ->103 writeDataPart(stream, lazyDataPart(request)).toDouble()104 }105 // Sum and Trailer106 val writtenLength = 0L +107 parameterLength +108 filesWithHeadersLength +109 stream.writeBoundary() + stream.writeString("--") +110 stream.writeNewline()111 // This is a buffered stream, so flush what's remaining112 writtenLength.toLong().also { stream.flush() }113 }114 }115 /**116 * Returns the length of the body in bytes117 * @return [Long?] the length in bytes, null if it is unknown118 */119 override val length: Long? by lazy {120 (121 // Parameters size122 request.parameters.sumByDouble { (name, data) ->123 writeParameter(ByteArrayOutputStream(), name, data).toDouble()124 } +125 // Blobs / Files size126 request.dataParts.sumByDouble { lazyDataPart ->127 val dataPart = lazyDataPart(request)128 // Allow for unknown sizes129 val length = dataPart.contentLength ?: return@lazy null130 if (length == -1L) return@lazy -1L131 0.0 + writeDataPartHeader(ByteArrayOutputStream(), dataPart) + length + CRLF.size132 } +133 // Trailer size134 "--$boundary--".toByteArray(DEFAULT_CHARSET).size + CRLF.size135 ).toLong()136 }137 private val boundary: String by lazy {138 request[Headers.CONTENT_TYPE].lastOrNull()139 ?.let { Regex("boundary=([^\\s]+)").find(it)?.groupValues?.getOrNull(1)?.trim('"') }140 ?: throw BoundaryMissing(request)141 }142 private fun writeParameter(outputStream: OutputStream, name: String, data: Any?): Long {143 outputStream.apply {144 return 0L +145 writeBoundary() +146 writeNewline() +147 writeString("${Headers.CONTENT_DISPOSITION}: form-data; name=\"$name\"") +148 writeNewline() +149 writeString("${Headers.CONTENT_TYPE}: text/plain; charset=\"${DEFAULT_CHARSET.name()}\"") +150 writeNewline() +151 writeNewline() +152 writeString(data.toString()) +153 writeNewline()154 }155 }156 private fun writeDataPart(outputStream: OutputStream, dataPart: DataPart): Long {157 outputStream.apply {158 val headerLength = writeDataPartHeader(outputStream, dataPart)159 val dataLength = dataPart.inputStream().use { it.copyTo(this) }160 return headerLength + dataLength + writeNewline()161 }162 }163 private fun writeDataPartHeader(outputStream: OutputStream, dataPart: DataPart): Long {...

Full Screen

Full Screen

UploadRequest.kt

Source:UploadRequest.kt Github

copy

Full Screen

...92 throw NotImplementedError("request.sources has been removed. Use request.add({ BlobDataPart(...) }, { ... }, ...) instead.")93 @Deprecated("Use request.add { FileDataPart(...)} instead", ReplaceWith("add(sourceCallback)"), DeprecationLevel.ERROR)94 fun source(sourceCallback: (Request, URL) -> File): UploadRequest =95 throw NotImplementedError("request.source has been removed. Use request.add { FileDataPart(...) } instead.")96 @Deprecated("Set the name via DataPart (FileDataPart, InlineDataPart, BlobDataPart) instead", ReplaceWith(""), DeprecationLevel.ERROR)97 fun name(nameCallback: () -> String): UploadRequest =98 throw NotImplementedError("request.name has been removed. Set the name via DataPart (FileDataPart, InlineDataPart, BlobDataPart) instead")99 @Deprecated("Set the name via DataPart (FileDataPart, InlineDataPart, BlobDataPart) instead", ReplaceWith(""), DeprecationLevel.ERROR)100 fun name(newName: String): UploadRequest =101 throw NotImplementedError("request.name has been removed. Set the name via DataPart (FileDataPart, InlineDataPart, BlobDataPart) instead")102}103fun Request.upload(): UploadRequest = UploadRequest.enableFor(this)...

Full Screen

Full Screen

FileRepository.kt

Source:FileRepository.kt Github

copy

Full Screen

1package xo.william.pixeldrain.repository2import android.util.Log3import androidx.lifecycle.*4import com.github.kittinunf.fuel.core.Request5import com.github.kittinunf.fuel.core.requests.UploadRequest6import xo.william.pixeldrain.api.FuelService7import xo.william.pixeldrain.database.File8import xo.william.pixeldrain.database.FileDao9import xo.william.pixeldrain.fileList.InfoModel10import com.github.kittinunf.result.Result11import kotlinx.serialization.decodeFromString12import kotlinx.serialization.json.Json13import xo.william.pixeldrain.fileList.InfoModelList14import java.io.InputStream15class FileRepository(private val fileDao: FileDao) {16 // Room executes all queries on a separate thread.17 private val fuelService = FuelService()18 private val format = Json { ignoreUnknownKeys = true }19 fun getDatabaseFiles(): LiveData<List<File>> {20 return fileDao.getAll()21 }22 fun insert(file: File) {23 fileDao.insert(file)24 }25 fun deleteFromDb(id: String) {26 return fileDao.deleteById(id)27 }28 fun uploadAnonPost(selectedFile: InputStream, fileName: String?): UploadRequest {29 return fuelService.uploadAnonFile(selectedFile, fileName)30 }31 fun uploadPost(selectedFile: InputStream, fileName: String?, authKey: String): UploadRequest {32 return fuelService.uploadFile(selectedFile, fileName, authKey)33 }34 fun loadFileInfo(file: File, loadedFiles: MutableLiveData<MutableList<InfoModel>>) {35 fuelService.getFileInfoById(file.id).responseString { _, _, result ->36 when (result) {37 is Result.Success -> {38 val infoFile = format.decodeFromString<InfoModel>(result.get())39 loadedFiles.value?.add(infoFile)40 loadedFiles.postValue(loadedFiles.value)41 }42 }43 }44 }45 fun loadApiFiles(loadedFiles: MutableLiveData<MutableList<InfoModel>>, authKey: String) {46 fuelService.getFiles(authKey).responseString { _, _, result ->47 when (result) {48 is Result.Success -> {49 val infoModelList = format.decodeFromString<InfoModelList>(result.get())50 loadedFiles.value?.addAll(infoModelList.files)51 loadedFiles.postValue(loadedFiles.value)52 }53 }54 }55 }56 fun deleteFromApi(id: String, authKey: String): Request {57 return fuelService.deleteFile(id, authKey)58 }59 fun deleteFromLoadedFiles(id: String, loadedFiles: MutableLiveData<MutableList<InfoModel>>) {60 val loadedFilesValue = loadedFiles.value61 if (!loadedFilesValue.isNullOrEmpty()) {62 loadedFilesValue.removeAll { it.id == id }63 loadedFiles.postValue(loadedFilesValue)64 }65 }66}...

Full Screen

Full Screen

FuelService.kt

Source:FuelService.kt Github

copy

Full Screen

...14 }15 fun uploadAnonFile(selectedFile: InputStream, fileName: String?): UploadRequest {16 val url = baseUri + "file";17 val setFileName = if (fileName !== null) fileName else "file";18 return Fuel.upload(url, method = Method.POST, parameters = listOf("name" to setFileName))19 .add(BlobDataPart(selectedFile, name = "file", filename = setFileName));20 }21 fun uploadFile(selectedFile: InputStream, fileName: String?, authKey: String): UploadRequest {22 val url = baseUri + "file";23 val setFileName = if (fileName !== null) fileName else "file";24 val authKeyCookie = "${authKeyCookie}=${authKey}";25 return Fuel.upload(url, method = Method.POST, parameters = listOf("name" to setFileName))26 .header(Headers.COOKIE to authKeyCookie).upload()27 .add(BlobDataPart(selectedFile, name = "file", filename = setFileName))28 }29 fun getFiles(authKey: String): Request {30 val url = "${baseUri}/user/files"31 val authKeyCookie = "${authKeyCookie}=${authKey}";32 return Fuel.get(url, parameters = listOf("page" to 0, "limit" to 1000))33 .header(Headers.COOKIE to authKeyCookie)34 }35 fun loginUser(username: String, password: String): Request {36 val url ="${baseUri}/user/login"37 return Fuel.post(url, parameters = listOf("username" to username, "password" to password));38 }39 fun deleteFile(id: String, authKey: String): Request {40 val url ="${baseUri}/file/${id}"41 val authKeyCookie = "${authKeyCookie}=${authKey}";42 return Fuel.delete(url).header(Headers.COOKIE to authKeyCookie)43 }44 fun getFileText(fileUrl: String): Request {45 return Fuel.get(fileUrl);46 }47}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Fuel automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful