代码之家  ›  专栏  ›  技术社区  ›  WISHY

在url更新中添加动态值

  •  0
  • WISHY  · 技术社区  · 4 年前

    我有以下网址

    URL TO CALL

    在界面中,我有

    @GET("storage/presigned-url?bucketName=files&key=payment-receipt/{fileName}&httpVerb=2&contentType=image/jpeg")
    suspend fun fileUploadPathCheque(@Path("fileName") name: String): Response<String>
    

    我想用一些值替换文件名

    我将函数调用为

    Api.fileUploadPathCheque(UUID.randomUUID().toString().plus(".jpg"))
    

    我得到以下例外

    ava.lang.IllegalArgumentException: URL query string "bucketName=files&key=payment-receipt/{fileName}&httpVerb=2&contentType=image/jpeg" must not have replace block. For dynamic query parameters use @Query.
    

    做这件事的正确方法是什么?

    1 回复  |  直到 4 年前
        1
  •  2
  •   mahdi    4 年前

    异常是不言自明的,您需要为 key .差不多

    @GET("storage/presigned-url?bucketName=files&httpVerb=2&contentType=image/jpeg")
    suspend fun fileUploadPathCheque(@Query("key") name: String): Response<String>`
    

    然后称之为追加 payment-receipt/ 要传递参数,请执行以下操作:

    Api.fileUploadPathCheque("payment-receipt/" + UUID.randomUUID().toString().plus(".jpg"))
    

    这应该对你有用。