Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Error when uploading a new version of an image attachment #130

Open
elliotlayden opened this issue Jan 15, 2021 · 7 comments
Open

Error when uploading a new version of an image attachment #130

elliotlayden opened this issue Jan 15, 2021 · 7 comments

Comments

@elliotlayden
Copy link

I have periodically received the following error when modifying an existing page using confl_create_post_from_Rmd(), with update = T. Manually re-uploading the attached images within the browser sometimes seems to fix the problem (allowing me to then upload further attachment versions via confl_create_post_from_Rmd). Otherwise, I have to delete and recreate the page. Any thoughts on what would cause this?

Checking the existing images...

Uploading the images...

Error: Error in paste(httr::http_condition(res, type = "error"), httr::content(res)): Bad Request (HTTP 400).
 400

Error in paste(httr::http_condition(res, type = "error"), httr::content(res)): Bad Request (HTTP 400).
 list(authorized = FALSE, valid = TRUE, errors = list(), successful = FALSE)

Error in paste(httr::http_condition(res, type = "error"), httr::content(res)): Bad Request (HTTP 400).
 com.atlassian.confluence.api.service.exceptions.BadRequestException: Cannot add a new attachment with same file name as an existing attachment:  <filename>

Run `rlang::last_error()` to see where the error occurred.
@yutannihilation
Copy link
Contributor

Hmm, curious. conflr checks the existing attachments and depending on whether there's the one with the same title (i.e., filename), it chooses the proper method. But, the error Cannot add a new attachment with same file name as an existing attachment indicates conflr failed to match the title for some reason. Do you know there's some conversion on the filename after uploading to your Confluence?

# Check if the images already exist
imgs_exist <- confl_list_attachments(id)
imgs_exist_ids <- purrr::map_chr(imgs_exist$results, "id")
names(imgs_exist_ids) <- purrr::map_chr(imgs_exist$results, "title")

img_id <- imgs_exist_ids[basename(imgs[i])]
if (is.na(img_id)) {
confl_post_attachment(id, imgs_realpath[i], minor_edit = minor_edit)
} else {
confl_update_attachment_data(id, img_id, imgs_realpath[i], minor_edit = minor_edit)
}

@elliotlayden
Copy link
Author

Thanks for responding so quickly. The filenames seem to be consistent between the Confluence attachments and what I have locally. For reference, I am using Atlassian Cloud. The issue also seems to be pretty intermittent. Sometimes I'm able to upload 3 different versions of a file before the issue occurs. Other times, I'm only able to upload one.

@stevenlockton-progenity

I am having a similar issue in which I use the "Post to Confluence" add-in on an already-published page (Confluence Cloud). If I have converted to the new editor (which is the default style for my organization) the images will not update. You get a grey square with a loading icon. It has become extremely inconvenient. We've been experiencing this problem for a week or two now.

One workaround is to delete the Confluence page and start from scratch. But not all users have delete permissions. I have had some success reverting back to the old editor in Page History, then updating, but this is clunky too.

@yutannihilation
Copy link
Contributor

@elliotlayden
Thanks for confirmation.

Sometimes I'm able to upload 3 different versions of a file before the issue occurs. Other times, I'm only able to upload one.

This sounds like there's some API limit and conflr fails to detect the error returned by the API, but I'm not sure...

@stevenlockton-progenity
Thanks for sharing, but it sounds a different issue to me. It's just that conflr doesn't support the new editor format yet (as you let us know in #125), right?

@stevenlockton-progenity
Copy link

stevenlockton-progenity commented Jan 26, 2021

@elliotlayden - hi - yes, I'm aware :) I was chipping in because this new issue is related to updating image attachments (albeit it only manifests itself in the new editor).

@lukocius
Copy link

lukocius commented Jan 18, 2022

confl_list_attachments <- function(id,
filename = NULL,
mediaType = NULL,
start = 0,
limit = 50,
expand = NULL)

# Check if the images already exist
imgs_exist <- confl_list_attachments(id)
imgs_exist_ids <- purrr::map_chr(imgs_exist$results, "id")
names(imgs_exist_ids) <- purrr::map_chr(imgs_exist$results, "title")

When uploading, there is no way to provide limit,
and it causes issues, if there are more than 50 images.

@yutannihilation
Copy link
Contributor

yutannihilation commented Jan 18, 2022

Ahh, thank you so much for catching!!!

confl_list_attachments() is used here to see if there's already the same name of the images; since it errors if we try to create the duplicated one, we need to the "update" API instead of the "create" API. So, probably it matters here...

Note that I'm not sure if that explains all the errors reported here, though. There might be something specific to the new editor.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants